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