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

前端 未结 3 580
一整个雨季
一整个雨季 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:29

    There is a frequently-seen idiom that goes as follows:

    public interface ResultItem> {
        public int getConfidence();
        public boolean equals(T item);
        public T cloneWithConfidence(int newConfidence);
    }
    
    public class IntResult implements ResultItem {
      //...
    }
    

提交回复
热议问题