Problems
Use the following problems to test your programming prowess on Java records. I strongly encourage you to give each problem a try before you turn to the solutions and download the example programs:
- Declaring a Java record: Write an application that exemplifies the creation of a Java record. Moreover, provide a short description of the artifacts generated by the compiler for a record behind the scenes.
- Introducing the canonical and compact constructors for records: Explain the role of the built-in record’s canonical and compact constructors. Provide examples of when it makes sense to provide such explicit constructors.
- Adding more artifacts in a record: Provide a meaningful list of examples about adding explicit artifacts in Java records (for instance, adding instance methods, static artifacts, and so on).
- Iterating what we cannot have in a record: Exemplify what we cannot have in a record (for instance, we cannot have explicit
private
fields...