O'Reilly logo

Java 9 Concurrency Cookbook - Second Edition by Javier Fernández González

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

If you want to implement a class that stores the first and last name of a person, you would normally implement something like this:

    public class PersonMutable {       private String firstName;       private String lastName;       private Date birthDate;        public String getFirstName() {         return firstName;       }        public void setFirstName(String firstName) {         this.firstName = firstName;       }        public String getLastName() {         return lastName;       }        public void setLastName(String lastName) {         this.lastName = lastName;       }       public Date getBirthDate() {         return birthDate;       }        public void setBirthDate(Date birthDate) {         this.birthDate = birthDate;       }      }

You can convert this class into an immutable class by following the rules explained earlier. The ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required