related to compile time error in record constructor
Pravin Jain
pravin at zensoftech.co.in
Wed Oct 7 05:16:48 UTC 2020
Dear sir,
In the following code, I have commented the error.
This error seems to be unnecessary, could have been a warning instead.
In the constructor of record access to instance variable before
explicit initialization, giving error, whereas same access is
available by invoking a method.
public record TestRecord(int low, int high) {
public TestRecord {
System.out.println(low);
// System.out.println(this.low); // error, variable not initialized
m1(); // but this works, why?
}
public void m1() {
System.out.println(this.low);
}
public static void main(String[] args) {
TestRecord r1 = new TestRecord(7,12);
}
}
--
Pravin Jain
(M)+91-9426054269
More information about the amber-dev
mailing list