A JDK enhancement proposal suggests the use of hyphenated keywords to denote new features in the Java language, with the goal of ensuring compatibility and readability in new keywords as suitable keyword tokens become increasingly scarce.
The draft JDK enhancement proposal for keyword management notes that new features in the Java language often require new keywords, but new keywords risk breaking existing programs. For balancing readability and compatibility, a new type of keyword could be used, namely a hyphenated keyword that is a compound of identifiers and pre-existing keywords. Examples cited were
break-with, and s
A keyword is a series of ASCII letters—such as
int—that developers are not allowed to use as identifiers in Java programs. Java uses a small set of keywords to denote fundamental language features. The keyword management proposal does not propose any new Java syntax elements or Java syntax optimizations for ease of implementation by compiler developers. The proposal has the following goals:
- Exploring syntactic options for Java language designers to denote new features.
- Solving a “perpetual” problem of keyword tokens being scare and expensive, leaving language designers to constrain or corrupt the Java programming model to fit available keywords.
- Advising language designers on the style of keyword suited to different features.
The proposal notes that Java designers face a challenge in that keywords conceived for Java 1.0 features are rarely suitable for new features. The proposal does carry risks in that some developers may not like hyphenated keywords, while others may accept the idea but dislike hyphenated suggestions that emerge for particular language features. This risk is expected to diminish over time.
The keyword proposal currently does not target a specific version of Java where it would be included. The proposal follows closely another JDK enhancement proposal to introduce records and sealed types in Java.