How does Java deal with the generic class in a non-generic way

Deal with legacy code

To handle the transition to generics, Java allows a generic class to be used without any type arguments.

Example

Here is an example that shows a raw type in action:


class MyClass<T> {
  T ob;/*  w  w  w  .j  av a 2 s  .  c o m*/
  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);
  }
}

Output:





















Home »
  Java Tutorial »
    Java Language »




Java Data Type, Operator
Java Statement
Java Class
Java Array
Java Exception Handling
Java Annotations
Java Generics
Java Data Structures