Posts

Showing posts with the label method references

Java 8 - Method references

Image
We'll add another field to our simple student management application. LocalDate birthday; Now the constructor of the class would look like this. Person(){} Person(String name, String emailAddress, int age, Sex gender,LocalDate birthday) {         this.name = name;         this.emailAddress = emailAddress;         this.age = age;         this.gender = gender;         this.birthday = birthday;  } We'll modify our student database with the new field. List<Person> peeps=new ArrayList<>(); LocalDate today=LocalDate.now(); peeps.add(new Person("Hasitha","hasitha@gmail.com",23,Sex.MALE,today)); peeps.add(new Person("Nadishan","nadishan@gmail.com",25,Sex.MALE,today.plus(1, ChronoUnit.DAYS))); peeps.add(new Person("Jayasundara","jayasundara@gmail.com",18,Sex.MALE,today.minusDays(2))); Somebody may tell you "Hey can you sort the students according to their b...