Generic Types
/**
* Creates a type SomeClass that takes * in a generic SomeType. SomeType can * be named anything.
*/
public class SomeClass<SomeType> {
private SomeType someThing;
public void someMethod(SomeType stuff) {
doStuff(stuff);
}
}
...
/** Creates a new instance of SomeClass, setting SomeType to String.
We don't need to put the type on the right since it's already
defined on the left. */
SomeClass<String> aClass = new SomeClass<>();Generic Subtypes
Type Bounds
Limitations of Generic Types
Last updated