Create a compareTo to a Generic Class that Implements Comparable

前端 未结 6 911
野趣味
野趣味 2020-12-31 01:29

I have a Generic Class with two type variables, which implements java.lang.Comparable.

public class DoubleKey implements Comparable

        
6条回答
  •  北荒
    北荒 (楼主)
    2020-12-31 01:47

    public class DoubleKey<
            K implements Comparable, 
            J implements Comparable> 
        implements Comparable> {
    
        public int compareTo(DoubleKey that){
            int cmp = this.key1.compareTo(that.key1);
            if(cmp==0) cmp = this.key2.compareTo(that.key2);
            return cmp;
        }
    }
    

提交回复
热议问题