path | title |
---|---|
/learnings/java_generics |
Learnings: Java: Generics |
class Thing {
public <T> void methodName( String thing, T whatsit ) {
}
}
public <T extends String> void fooBar(T) { ... }
public <T extends String & Runnable> void foobar(T) { ... }
The &
signals that the class must implement that thing.
If you want to just check for interface implementation can do extends Object & Runnable
.
See also:
- <<Kotlin_Type_Erasure>>