Raw Types
Explore raw types in Java generics to understand their role in legacy code before JDK 5. Discover how omitting type parameters creates raw types, which compile but generate unchecked operation warnings. Learn why raw types produce compiler warnings and how type inference works when types are omitted.
We'll cover the following...
We'll cover the following...
Technical Quiz
1.
Consider the Printer class below, which is parametrized on type T.
public class Printer<T> {
T item;
public Printer(T item) {
this.item = item;
}
public void consolePrinter() {
System.out.println(item.toString());
}
public void changeItem(T item) {
this.item = item;
}
}
Will the following code snippet compile, if no type arguments are supplied?
Printer printer = new Printer(5);
A.
Yes
B.
No
1 / 4
The snippet Printer printer = new Printer(5); will compile just fine. When the actual type parameter is omitted, a raw type is created. Raw ...