I have a Cage class:
public class Cage {
// the construtor takes in an integer as an explicit parameter
...
}
I am
For other java newbie like me.
public class ContinuousAddressBuilder<T> extends VariableLengthPacket {
...
/* T=int/float/double */
private ArrayList<T> informosomes;
...
public ContinuousAddressBuilder builderCon(int con) {
...
}
}
Add <T>
after your class:
change from
public ContinuousAddressBuilder builderCon(int con)
to
public ContinuousAddressBuilder<T> builderCon(int con)
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.