From the course: Migrating beyond Java 8
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Java 14 language and API features - Java Tutorial
From the course: Migrating beyond Java 8
Java 14 language and API features
- [Instructor] Java 14 introduced several new features and preview features to the language that we'll explore in this lesson. One preview feature is records. Records help us cut down on boilerplate code found in domain classes. If we take a look at this simple Cat class, you'll notice it's about 60 lines of code, just for two fields, a constructor, some accessors, a hashcode, an equals method and a two string method. Using a record, we can get rid of all this code and automatically generate these members. So I'm going to go ahead and delete our Cat class and then we're going to declare a record. So the first thing that we need to do is specify an access modifier and then we use the record type and then specify the name of our record. In this case, Cat. Then we're going to specify the fields that we would like on our record and then we simply end the record with an open and closing curly brace. That's all it takes…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.