Page 1 of 1

About Question enthuware.ocpjp.v17.2.3692

Posted: Tue Dec 27, 2022 9:45 am
by theujior
1st option explains
You may provide any number of constructors in a record. However,
1. if you provide a non-canonical constructor, you must also provide a canonical constructor (because the compiler will not provide it automatically now)
JLS 8.10.4. Record Constructor Declarations says:
If a canonical constructor is not explicitly declared in the declaration of a record class R, then a canonical constructor r is implicitly declared in R with the following properties:...
Can't you compile a record class with non-canonical constructor and no explicitly declared canonical constructor as following?

Code: Select all

public record Student(int id, String name){
    public Student(){ //non-canonical constructor
        this(10, "");
    }
}

Re: About Question enthuware.ocpjp.v17.2.3692

Posted: Tue Dec 27, 2022 10:24 am
by admin
You are right. The explanation is incorrect about the constructors. Must be fixed asap.

thank you for your feedback!