implementing Comparable interface from abstract class with concrete subclasses

℡╲_俬逩灬. 提交于 2019-12-03 21:09:27

Change the line

public abstract class GeometricObject implements Comparable {

to

public abstract class GeometricObject implements Comparable<GeometricObject> {

Without generics, the method you need to implement is compareTo(Object), not compareTo(GeometricObject)

It's always good to use the @Override annotation whenever you are implementing or overriding some method.

public abstract class GeometricObject implements java.lang.Comparable<GeometricObject> {

    @Override
    public int compareTo(GeometricObject o) {
        int result = 0;
        //do comparision
        return result;
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!