Demonstrate the non generic class : Generic Class « Generics « Java






Demonstrate the non generic class

Demonstrate the non generic class
   
class NonGen {  
  Object ob; 
    
  NonGen(Object o) {  
    ob = o;  
  }  
  
  Object getob() {  
    return ob;  
  }  
  void showType() {  
    System.out.println("Type of ob is " +  
                       ob.getClass().getName());  
  }  
}  
  
 
public class NonGenDemo {  
  public static void main(String args[]) {  
    NonGen integerObject;   
    integerObject = new NonGen(88);  
  
    integerObject.showType(); 
 
    int v = (Integer) integerObject.getob();  
    System.out.println("value: " + v);  
  
 
    NonGen strOb = new NonGen("Non-Generics Test");  
    strOb.showType(); 
 
    String str = (String) strOb.getob();  
    System.out.println("value: " + str);  
 
    integerObject = strOb; 
    v = (Integer) integerObject.getob(); 
  }  
}


           
         
    
    
  








Related examples in the same category

1.A simple generic class. A simple generic class.
2.Stats attempts (unsuccessfully) to create a generic class
3.A simple generic class hierarchy.A simple generic class hierarchy.
4.A nongeneric class can be the superclass of a generic subclass.A nongeneric class can be the superclass of a generic subclass.
5.Use the instanceof operator with a generic class hierarchy. Use the instanceof operator with a generic class hierarchy.
6.Java hierarchy generic classJava hierarchy generic class
7.Custom Generic Object TesterCustom Generic Object Tester
8.Pair of template arguments
9.Generic pair structure
10.Simple STL Pair Implementation