Sealed interfaces in qualified anonymous class instances - minor spec addition?
Manoj Palat
manoj.palat at in.ibm.com
Sat Jun 20 11:30:01 UTC 2020
Hi,
>From jep 360 Section 15.9.1 [ http://cr.openjdk.java.net/~gbierman/jep360/jep360-20200526/specs/sealed-classes-jls.html#jls-15.9.1] second bullet, ie:
“If the class instance creation expression is qualified, then:
The Identifier in ClassOrInterfaceTypeToInstantiate must unambiguously denote an inner class that is accessible, non-final, non-sealed, not an enum type, and a member of the compile-time type of the Primary expression or the ExpressionName. Otherwise, a compile-time error occurs”,
I think we should add “or an interface that is non-sealed “ after enum type similar to the earlier bullet for completeness’ sake as illustrated in the code below
public class X {
public static void main(String[] args) {
new A.IY() {}; // Error since IY is sealed
}
}
class A {
sealed interface I permits IY{}
sealed interface IY extends I permits Z {}
final class Z implements IY{}
}
Regards,
Manoj
More information about the amber-spec-experts
mailing list