< prev index next > test/langtools/tools/javac/SuperInit/SuperInitFails.java
Print this page
/*
* @test /nodynamiccopyright/
* @bug 8194743
* @summary Permit additional statements before this/super in constructors
* @compile/fail/ref=SuperInitFails.out -XDrawDiagnostics SuperInitFails.java
+ * @enablePreview
*/
import java.util.concurrent.atomic.AtomicReference;
public class SuperInitFails extends AtomicReference<Object> implements Iterable<Object> {
private int x;
super(); // this should FAIL
};
}
public SuperInitFails(int[][] z) {
! super((Runnable)() -> x); // this should FAIL
}
public SuperInitFails(long[][] z) {
super(new Inner1()); // this should FAIL
}
super(); // this should FAIL
};
}
public SuperInitFails(int[][] z) {
! super((Runnable)() -> System.err.println(x)); // this should FAIL
}
public SuperInitFails(long[][] z) {
super(new Inner1()); // this should FAIL
}
public SuperInitFails(double[][] x) {
Runnable r = () -> this.x = 7; // this should FAIL
super();
}
+ public int xx;
+
+ SuperInitFails(short[][] ignore) {
+ int i = new SuperInitFails(){
+ void foo() {
+ System.err.println(xx); // this should fail
+ }
+ }.xx; // this one is OK though
+ super(null);
+ }
+
public static class Inner4 {
Inner4() {
Runnable r = () -> {
class A {
A() {
}
};
super();
};
}
+
+ static class Inner5 {
+ int x = 4;
+ static String m1(Runnable r) { return null; }
+ static String m2(Object r) { return null; }
+ Inner5() {
+ m1(() -> System.out.println(x)).toString();
+ m2(x).toString();
+ super();
+ }
+ }
+
+ static class Inner6 {
+ Inner6() {
+ class Bar {
+ Bar() {
+ Object o = Bar.this;
+ super();
+ }
+ }
+ super();
+ }
+ }
}
< prev index next >