Type a compareTo using Integer.compare
Type a compareTo using Integer.compare
Answer
@Override public int compareTo(Student other) { return Integer.compare(this.gpa, other.gpa); }
Integer.compare avoids integer overflow bugs that bite this.gpa - other.gpa. Returns negative/zero/positive as required by the Comparable contract.