The two utilities described in this section are as follows:
- java.util.Objects
- org.apache.commons.lang3.ObjectUtils
They are especially useful during class creation, so we will concentrate largely on the methods related to this task.
The two utilities described in this section are as follows:
They are especially useful during class creation, so we will concentrate largely on the methods related to this task.
The Objects class has only 17 methods that are all static. Let's look at some of them while applying them to the Person class. Let's assume this class will be an element of a collection, which means it has to implement the equals() and hashCode() methods:
class Person {
private int age;
private String name;
public Person(int age, String name) {
this.age = age;
this.name = name;
}
public int getAge(){ return this.age...