Inferred type is not a valid substitute for a Comparable generic type

前端 未结 4 1961
感动是毒
感动是毒 2021-01-11 11:11

Consider the code:

public abstract class Item implements Comparable
{
    protected T item;

    public int compareTo(T o)
    {
        re         


        
4条回答
  •  抹茶落季
    2021-01-11 11:25

    Just change the class like follow:

         public class MyItem extends Item implement Comparable>
         {
             T object;
         }
    

    Or

           public abstract class Item implements Comparable>
           {
               protected T item;
    
               public int compareTo(MyItem o)
               {
                  return 0; // this doesn't matter for the time being
           }
    

    }

    The error tips has shown us.Hope it helpful.

提交回复
热议问题