You already know what the erasure is. The erasure is written |T|
, so |List<String>|
is List
. Type variables, meaning mentionings of formal type parameters, are erased to the erasure of their left-most bound. The most general form of a formal type parameter T
is T extends A1 & A2 & ...
, where A1
to An
are T
s bounds.
For Example
public abstract class Copyable<T extends Copyable<T> & Cloneable> {
public T copy() { /* ... */ }
}
The T
in copy would be erased to the erasure of its left-most bound. That is |Copyable<T>| = Copyable
.
Simpler bounds may be
- single bound as in
class Enum<E extends Enum<E>>
: The left most bound is the single bound, the erasure is|Enum<E>| = Enum
. - no bound as in
class ArrayList<E>
:E
really has an implicit bound ofObject
(class ArrayList<E extends Object>
), so the erasure is|Object| = Object
.
Edit: In case of a List<? extends Foo>
you'd be erasing the entire thing; and the erasure of List<? extends Foo>
is |List|
.