4 ms·
Can 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 conf
by chrisseaton 7y ago
Can 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.