I keep getting this error in my user class:
User is not abstract and does not override abstract method compareTo(User) in Comparable
I’m not sure what it means or what to do to make it work. I did look on other similar posts but don’t really understand the responses since they are most of the time specific to someone elses code. I can provide more information about what I’m trying to do if required.
public class User implements Comparable < User > {
private String firstName;
private String surname;
private int booksOut;
User(String inFirstName, String inSurname, int inBooksOut){
this.firstName = inFirstName;
this.surname = inSurname;
this.booksOut = inBooksOut;
}
//...
}
What i am essentially doing I am creating SortedLinkedList class from LinkedList and I have add method in there which uses compareTo, to order the data in ascending order as they are added.
So when I call
User user1= new User("Dan", "Hill", 0);
SortedLinkedList LibraryUser = new SortedLinkedList();
LibraryUser.add(user1);
It creates new object which is saved in the sorted linked list.
When you implement Comparable, java looks for the implementation of compareTo
For example:
(Please note that I made the variables public for simplicity)