About Question enthuware.ocpjp.v17.2.3692

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
theujior
Posts: 11
Joined: Fri Sep 09, 2022 8:41 am
Contact:

About Question enthuware.ocpjp.v17.2.3692

Post 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, "");
    }
}

admin
Site Admin
Posts: 10384
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.v17.2.3692

Post by admin »

You are right. The explanation is incorrect about the constructors. Must be fixed asap.

thank you for your feedback!

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests