I’m trying to understand this notation of whats going on here Example also below. I’m looking to see if anyone can supply additional code to help me make sense of this. How do I extend junk with T? what does that imply?
public class Junk<T extends Junk>
{
public Junk()
{
}
public T returnType()
{
return null; //? what would I even return
}
//what would I do to make sense of this class
}
Tis a generic type parameter. You know it is a Junk, or a subclass of it. To return anything useful from your method, you’d need some other methods using the same type. For example:It can be used by creating instances where the type parameter is specified:
This is more useful than simply using “Junk” instead of “T”, because subtypes can be used without losing type-safety. If you have a subclass
SubclassJunk, then you can do: