Unboxing issues

前端 未结 2 1804
旧巷少年郎
旧巷少年郎 2021-01-06 18:20

I have a class that extends the LinkedList class. Here\'s an excerpt of the code:

class SortedList extends LinkedList {
      i         


        
2条回答
  •  一整个雨季
    2021-01-06 19:07

    The problem is that you've declared Integer as a generic type parameter for the SortedList class. So when you refer to Integer as a parameter of the intMethod method, that means the type parameter, not the java.lang.Integer type which I suspect you meant. I think you want:

    class SortedList extends LinkedList {
        int intMethod(Integer integerObject){
            return integerObject;
        }
    }
    

    This way a SortedList is always a list of integers, which I suspect is what you were trying to achieve. If you did want to make SortedList a generic type, you would probably want:

    class SortedList extends LinkedList {
        int intMethod(Integer integerObject){
            return integerObject;
        }
    }
    

提交回复
热议问题