5 ms·
Doesn't adding a "record" keyword break a lot of existing code? It wasn't a keyword as recently as JDK 8 (https://docs.oracle.com/javase/tutorial/java/nutsandbo
by jfengel 7y ago
Doesn't adding a "record" keyword break a lot of existing code? It wasn't a keyword as recently as JDK 8 (https://docs.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html https://docs.oracle.com/javase/tutorial/java/nutsandbolts/_k...).
- chrisseaton 7y agoCan you give an example of some code it'd break? At what points in a valid legal Java program could you have previously written record, where it would now conflict with this keyword in the locations where it is valid?
- Macha 7y agoUnless the rules of keywords have changed: Map<String, String> record = getSomeData(); This should no longer be valid if record is a keyword?
- chrisseaton 7y agoBut a record keyword isn't valid where you've written it there. So isn't it still an identifier?
- Macha 7y agoNo, keywords are banned as identifiers everywhere, not just in ambiguous contexts.
- chrisseaton 7y agoI don't believe that's true. boolean isRecordStart() { if (token.kind == IDENTIFIER && token.name() == names.record && (peekToken(TokenKind.IDENTIFIER, TokenKind.LPAREN) || peekToken(TokenKind.IDENTIFIER, TokenKind.LT))) { checkSourceLevel(Feature.RECORDS); return true; } else { return false; } https://github.com/openjdk/amber/blob/4f5927ba8f23c2e40ac467809ef83b7395084355/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java#L4114-L4122 https://github.com/openjdk/amber/blob/4f5927ba8f23c2e40ac467...
- dmead 7y agowouldn't this be true any time an English language keyword is added to a language?
- Macha 7y agoYes. It's not a very frequent occurrence. Here are all new keywords added to the language: Java 2: strictfp Java 4: assert Java 5: enum Java 9: module, requires Java 13: yield Java 15: record Now my local Java dev env is only Java 8, but I'm not allowed declare String enum = "foo"; which would have been valid prior to its addition as a keyword.
- Reason077 7y agoAlthough enums weren't introduced until Java 5, enum was always a reserved word in Java. module, requires, yield, and record are not reserved words, and can still be used as names for members etc.
- _old_dude_ 7y ago> enum was always a reserved word in Java Nope, i had to patch a bunch of codes because enum was not a reserved keyword until it was introduced in Java 5.
- chrisseaton 7y ago> enum was always a reserved word in Java This isn't true. It isn't listed in the list of keywords in Section 3.9 of the 1996 Java specification.
- Reason077 7y agoMy apologies, you are right. I was confusing it with const, which has always been a reserved word (despite never being used).
- mason55 7y ago> Unless the rules of keywords have changed Keywords are context dependent nowadays. In the context you've provided record would not be treated as a keyword.
- kasperni 7y agoThe keywords you refer to in your link are all "classic" keywords. The last one that was added was "assert" with Java 1.4, which broke a lot of code. And made people realize that adding new "classic" keywords was a bad idea. Now, Java only adds contextual keywords. Which are basically a sequence of Java letters that are tokenized as a keyword in certain contexts but as an identifier in all other contexts. var, record, inline, module, ect. are examples hereof. You can read more about it in this JEP Draft about "keyword management for the Java Language": https://openjdk.java.net/jeps/8223002 https://openjdk.java.net/jeps/8223002
- fctorial 7y agoIt shouldn't be that big of a deal. Renaming is easy as pie in java codebases.