Panama will preview an instance method in a well-known abstract class in java.*. The implementation of the preview method just throws, so that clients which already subclass the abstract class are not broken, but new Panama-aware clients will want to override the preview method.
Overriding a preview method is akin to invoking it -- neither should be allowed if preview features are disabled. I have updated JEP 12 to clarify this point: "When compiling with preview features disabled, any source code reference to ... (iii) a normal preview API (whether referenced by name, or invoked, or overridden), causes a compile-time error."
At present, with preview features disabled, javac allows a preview method to be overridden without warning or error. In the code below, javac is silent at 1 and 2, but rightly gives an error at 3. There should be errors at 1, 2, and 3. With preview features enabled, there should be preview warnings at 1, 2, and 3.
class Test {
public static void main(String[] args) {
// Assume Iterable declares a preview instance method `mumble`
class MyIterable implements Iterable {
public java.util.Iterator iterator() { return null; }
@Override public void mumble() { } // 1
}
MyIterable it = null;
it.mumble(); // 2
Iterable it2 = null;
it2.mumble(); // 3
}
}
Overriding a preview method is akin to invoking it -- neither should be allowed if preview features are disabled. I have updated JEP 12 to clarify this point: "When compiling with preview features disabled, any source code reference to ... (iii) a normal preview API (whether referenced by name, or invoked, or overridden), causes a compile-time error."
At present, with preview features disabled, javac allows a preview method to be overridden without warning or error. In the code below, javac is silent at 1 and 2, but rightly gives an error at 3. There should be errors at 1, 2, and 3. With preview features enabled, there should be preview warnings at 1, 2, and 3.
class Test {
public static void main(String[] args) {
// Assume Iterable declares a preview instance method `mumble`
class MyIterable implements Iterable {
public java.util.Iterator iterator() { return null; }
@Override public void mumble() { } // 1
}
MyIterable it = null;
it.mumble(); // 2
Iterable it2 = null;
it2.mumble(); // 3
}
}
- csr for
-
JDK-8283380 javac should constrain more uses of preview APIs
-
- Closed
-