> Sorry, I know I’ve said this before, but I guess not on this thread. Local > records are always implicitly static — they cannot capture anything. (Local > enums would be the same way.) As you point out, the hidden state would > undermine the “the record description is the state, the whole state, and > nothing but the state” directive.
Thank you for the explanation. I saw this wording in the spec draft [1] but it sounds unclear, at least to me. We never had local static classes, so I'm not sure that "implicitly static" is enough explanation for "they cannot capture anything". Another unclear item is whether they can use compile-time constants that refer to surrounding local variables. E.g.: public static void main(String[] args) { final double TWO_PI = Math.PI * 2; record Circle(Point center, double radius) { double circumference() { return TWO_PI * radius; // allowed? } } } So I think this part of the spec should be more verbose, probably including some examples. I expect a wording like this: "It's a compile-time error if a local record refers to a local variable or parameter declared outside of the record, except (or including) compile-time constants" With best regards, Tagir Valeev. [1] http://cr.openjdk.java.net/~gbierman/jep359/jep359-20191031/specs/records-jls.html#jls-14.3