sudom82 sudom82 - 1 year ago 76
Java Question

Java: Class's type parameter extending its own subclass

could I get an explanation for what this method signature is doing?

AbstractRoad<T extends AbstractRoad.Builder<T>>

where there is a subclass called Builder in AbstractRoad's class.

So AbstractRoad has a type parameter..that extends it's own subclass to allow the class to do what exactly?

Answer Source

It looks like the type parameter is an extension of the Builder... meaning it is expecting any type that is or extends the Builder Subclass

ArrayList<Inventory<T extends Item>>

This is an array list of inventories containing items or objects that extend item... i.e.

Public class Potion extends Item

would be a valid item in the inventory... T is a generics reference of essentially Object. Please see this link: Generic Types

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download