Raw type. References to generic types should be parameterized

前端 未结 2 1763
感动是毒
感动是毒 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 14:54

    For other java newbie like me.

    • Code is look like this:
    public class ContinuousAddressBuilder<T> extends VariableLengthPacket {
      ...
    
      /* T=int/float/double */
      private ArrayList<T> informosomes;
    
      ...
    
      public ContinuousAddressBuilder builderCon(int con) {
        ...
      }
    }
    
    • Solution:

    Add <T> after your class:

    change from

    public ContinuousAddressBuilder builderCon(int con)

    to

    public ContinuousAddressBuilder<T> builderCon(int con)

    0 讨论(0)
  • 2020-12-10 15:07

    Cage<T> 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<Dog> cage5 = new Cage<Dog>(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<Animal>. However, you should still explicitly state the type parameter even if this is what you want.

    0 讨论(0)
提交回复
热议问题