I have an Author class written like this:
public final class Author implements Comparator<Author> {
private final String authorFirstname;
private final String authorLastname;
public Author(String authorFirstname, String authorLastname){
this.authorFirstname = authorFirstname;
this.authorLastname = authorLastname;
}
//Left out equals/HashCode
@Override
public int compare(Author o1, Author o2) {
// TODO Auto-generated method stub
return this.authorLastname.compareTo(o2.getLastname());
}
}
I want to store them in a List
collection and sort them by last name. I've read Java 8 comparable, these two examples(1,2). Have I implemented it correctly?