Andrew Andrew - 4 years ago 119
Java Question

compareTo method without an abstract class

I need to call the method compareTo from a class that I made, but I cannot make this class abstract. So when I try to call compareTo, it says that the class isn't abstract and that it dosent override the compareTo method. How do you work around this? This is an assignment and I cannot post code, but this is the method header:

class Customer implements Comparable<Object>


and my compareTo method looks like this:

@Override
public int compareTo(Customer c)
{
//comparison
}

Answer Source

Your class implements the wrong generic interface. If you want it to be comparable to itself, it should implement Comparable<Customer>.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download