Accessing compile-time constants from local interfaces/enums
Tagir Valeev
amaembo at gmail.com
Mon Jun 15 10:43:04 UTC 2020
Hello!
I want to get back to this inconsistency that appeared with local
records. Now it looks even more striking. See (tried 15-ea+26-1287):
public class Test {
public static void main(String[] args) {
final int x = 5;
class C {
static final int CONST = x; // compiles fine: CONST is in static
context but can refer to local x
}
}
}
public class Test {
public static void main(String[] args) {
final int x = 5;
interface I {
static final int CONST = x; // non-static variable x cannot be
referenced from a static context
}
}
}
I think the spec and implementation should be made more consistent
here. Namely, allow references to compile-time constants referenced
via locals in both cases. Or disallow in both cases (though this would
be a breaking change).
What do you think?
With best regards,
Tagir Valeev.
More information about the amber-spec-experts
mailing list