June 2018
Beginner
722 pages
18h 47m
English
The class Objects has only 17 methods—all static. We have already used some of them in the previous chapter when we implemented the class Person:
class Person implements Comparable<Person> { private int age; private String name; public Person(int age, String name) { this.age = age; this.name = name == null ? "" : name; } public int getAge(){ return this.age; } public String getName(){ return this.name; } @Override public int compareTo(Person p){ int result = this.name.compareTo(p.getName()); if (result != 0) { return result; } return this.age - p.getAge(); } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null) return false; if(!(o instanceof Person)) return false; Person person = (Person)o ...
Read now
Unlock full access