Raw type. References to generic types should be parameterized

前端 未结 2 1788
感动是毒
感动是毒 2020-12-10 14:35

I have a Cage class:

public class Cage {
// the construtor takes in an integer as an explicit parameter
...
}

I am

2条回答
  •  天涯浪人
    2020-12-10 15:07

    Cage is a generic type, so you need to specify a type parameter, like so (assuming that there is a class Dog extends Animal):

    private Cage cage5 = new Cage(5);
    

    You can use any type that extends Animal (or even Animal itself).

    If you omit the type parameter then what you wind up with in this case is essentially Cage. However, you should still explicitly state the type parameter even if this is what you want.

提交回复
热议问题