Generic types in Java is backward compatible.
The non-generic version of a generic type is called a raw type.
If you use raw types, the compiler will generate unchecked warnings:
Wrapper rawType = new Wrapper("Hello"); // An unchecked warning Wrapper<String> genericType = new Wrapper<String>("Hello"); genericType = rawType; // An unchecked warning rawType = genericType;
public class Main { public static void main(String[] args) { Wrapper rawType = new Wrapper("Hello"); // An unchecked warning Wrapper<String> genericType = new Wrapper<String>("Hello"); genericType = rawType; // An unchecked warning rawType = genericType;/*from w w w . j a v a 2s . c o m*/ } } class Wrapper<T> { private T ref; public Wrapper(T ref) { this.ref = ref; } public T get() { return ref; } public void set(T a) { this.ref = a; } }