Raw Types and Legacy Code
To handle the transition to generics, Java allows a generic class to be used without any type arguments.
Here is an example that shows a raw type in action:
class MyClass<T> {
T ob;
MyClass(T o) {
ob = o;
}
T getob() {
return ob;
}
}
public class Main {
public static void main(String args[]) {
MyClass raw = new MyClass(new Double(98.6));
double d = (Double) raw.getob();
System.out.println("value: " + d);
}
}
Home
Java Book
Language Basics
Java Book
Language Basics
Generics:
- Generic Class
- Generic Bounded Types
- Generic Wildcard Arguments
- Generic Bounded Wildcards
- Generic Method
- Generic Constructors
- Generic Interfaces
- Raw Types and Legacy Code
- Generic Class Hierarchies
- Run-Time Type Comparisons Within a Generic Hierarchy
- Overriding Methods in a Generic Class
- Generic Restrictions
- Generic Array Restrictions