-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
24
-
openjdk version "24-ea" 2025-03-18
OpenJDK Runtime Environment (build 24-ea+30-3590)
OpenJDK 64-Bit Server VM (build 24-ea+30-3590, mixed mode, sharing)
Consider:
{code:java}
public interface A {
static A localSingleton() {
class B implements A {
private static final A INSTANCE = new B();
}
return B.INSTANCE;
}
}
{code}
The idea is to avoid exposing publicly class B (as classes declared in interfaces are `public` by default).
The class above compiles with Java 23 and less, but fails with Java 24-ea+30 with:
{noformat}
A.java:4: error: local class B cannot be instantiated from a static context
private static final A INSTANCE = new B();
^
1 error
{noformat}
{code:java}
public interface A {
static A localSingleton() {
class B implements A {
private static final A INSTANCE = new B();
}
return B.INSTANCE;
}
}
{code}
The idea is to avoid exposing publicly class B (as classes declared in interfaces are `public` by default).
The class above compiles with Java 23 and less, but fails with Java 24-ea+30 with:
{noformat}
A.java:4: error: local class B cannot be instantiated from a static context
private static final A INSTANCE = new B();
^
1 error
{noformat}
- relates to
-
JDK-8325805 Compiler Implementation for Flexible Constructor Bodies (Second Preview)
-
- Resolved
-