< prev index next >

test/langtools/tools/javac/DefiniteAssignment/DA_DUConstructors.java

Print this page

 1 /*
 2  * @test /nodynamiccopyright/
 3  * @bug 8325805
 4  * @summary Permit non-superclass instance field assignments before this/super in constructors
 5  * @compile/fail/ref=DA_DUConstructors.out -XDrawDiagnostics DA_DUConstructors.java
 6  */
 7 
 8 public class DA_DUConstructors {
 9     // identity
10     class C1 {
11         final int x;
12         final int y = x + 1;
13         C1() {
14             x = 12;
15             super();
16         }
17     }
18 
19     class C2 {



20         final int x;
21         C2() {
22             this(x = 3); // error
23         }
24         C2(int i) {
25             x = 4;
26         }
27     }
28 
29     class C3 {
30         C3(int i) {}
31     }
32     class C4 extends C3 {
33         final int x;
34         C4() {
35             super(x = 3); // ok
36         }
37     }
38 
39     class C5 {
40         final int x;
41         final int y = x + 1; // x is not DA
42         C5() {
43             x = 12; super();
44         }

 1 /*
 2  * @test /nodynamiccopyright/
 3  * @bug 8324873 8325805
 4  * @summary Permit non-superclass instance field assignments before this/super in constructors
 5  * @compile/fail/ref=DA_DUConstructors.out -XDrawDiagnostics DA_DUConstructors.java
 6  */
 7 
 8 public class DA_DUConstructors {
 9     // identity
10     class C1 {
11         final int x;
12         final int y = x + 1;
13         C1() {
14             x = 12;
15             super();
16         }
17     }
18 
19     class C2_Base {
20         C2_Base(int i) {}
21     }
22     class C2 extends C2_Base {
23         final int x;
24         C2() {
25             super(x = 3); // error


26             x = 4;
27         }
28     }
29 
30     class C3 {
31         C3(int i) {}
32     }
33     class C4 extends C3 {
34         final int x;
35         C4() {
36             super(x = 3); // ok
37         }
38     }
39 
40     class C5 {
41         final int x;
42         final int y = x + 1; // x is not DA
43         C5() {
44             x = 12; super();
45         }
< prev index next >