How can I make an interface instance method accept arguments of the same class only?

前端 未结 3 610
一整个雨季
一整个雨季 2020-12-30 11:45

I want to use an interface like this :

public interface ResultItem {
    public int getConfidence();
    public boolean equals(ResultItem item);
    public R         


        
3条回答
  •  没有蜡笔的小新
    2020-12-30 12:30

    Well, you could make it generic:

    public interface ResultItem> {
        public boolean equals(ResultItem item);
    }
    

    Then you would need to make IntResult implement ResultItem.

    Of course that doesn't stop another class from misbehaving, e.g. FloatResult implementing ResultItem but it makes various bits of API work when all the classes are well behaved.

提交回复
热议问题