Trying out some code with record and record components. I was making use of the variable rarity components and was struck with a compile-time error over a custom constructor.
public record Break<R extends Record>(R record, String... notifications) {
public Break(R record, String... notifications) {
System.out.println("record: " + record + " and notifications: " + Arrays.toString(notifications));
this.record = record;
this.notifications = notifications;
}
// compile error: non canonical record constructor must delegate to another costructor
public Break(R record) {
System.out.println("record: " + record);
this.record = record;
}
public Break() {
this(null); // this works
// actually intelliJ suggests it uses the constructor that is not compiling
}
public static void main(String[] args) {
new Break<>(new Break<>());
}
}
What I am curious to understand is, how is the similar constructor inferred when invoked via another custom constructor without any components provided for initialization.