On Thu, 30 Apr 2026 09:33:28 GMT, Maurizio Cimadamore <[email protected]> wrote:
>> This is the proposed patch for Enhanced Local Variable Declarations >> (Preview). >> >> - [x] I confirm that I make this contribution in accordance with the >> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai). > > src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java > line 3306: > >> 3304: return VariableDeclKind.LocalVarDecl; >> 3305: } >> 3306: else if(peekToken(lookahead, COLON) || // in >> the init part of an enhanced for loop > > This will also allow ELVD in a non-for each loop, right? E.g. for (P(int x) = bar ; ; ) { } > src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java > line 3367: > >> 3365: protected boolean hasDisallowedModifiers(JCModifiers mods) { >> 3366: return mods != null >> 3367: && (mods.annotations.nonEmpty() || (mods.flags & >> Flags.FINAL) != 0); > > Question -- I understand why we reject `final`. By the same token, I'd also > reject `volatile` or `transient` or any modifier that refers to storage > semantics. The issue here is that there's no (outer) variable being declared > -- so IMHO would be simpler to assume no modifiers? nvm -- this only goes on local vars, so the only modifier that can appear there is `final`. All good. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/30556#discussion_r3166980246 PR Review Comment: https://git.openjdk.org/jdk/pull/30556#discussion_r3167013499
