Suppose we have a generic declaration
interface Foo<T>
T get();
void set(T);
void bet();
A raw type Foo
is equivalent to a type declared as
interface Foo
Object get();
void set(Object);
void bet();
// all generics info are stripped
For example, in Java 5 we have List<E>
, its raw version List
contains the exact same method signatures as the pre-java5 List
interface. Raw type is used for backward compatibility.
Raw List
is pretty close to List<Object>
; but very different from List<?>
An object foo
of type Foo<?>
has the type of
interface Foo<X>
X get();
void set(X);
void bet();
for some definitive, albeit unknown, type X. Though X is unknown, we can still invoke foo.get()
and foo.bet()
. But we can't invoke foo.set(a)
because there's no way to know whether a
is of the unknown type X
- unless a
is null
.