18 Generics

JDK1.5 phenomena.

Deformity writing:

1. List<String> list=new ArrayList();

2. List list=new ArrayList<String>();

JDK1.7 began to support List <String> list = new ArrayList ();  so written, can be pushed back from the front to the back of the specific type of

Generic erasure: generic type of data may support any type to the particular type occurs at compile time the java

public  class fanxing {
     public  static  void main (String [] args) { 
        TDemo <String> T = new new TDemo <String> (); 
        TT = "Xu Wang riding" ; 
    } 


} 
// custom generic class
 // class name <identifier>
 // Although you can easily write, but we usually use capital letters 
/ * 
 * ---- elements E element 
 * T ---- type type 
 * R ---- result result 
 * K ----- key 
 * V ----- value 
 * 
 * / 
class TDemo <E> {
     // properties 
    E T; // attribute type may be any type of reference
     //E t1 = new E (); This is incorrect given type may not create object reference example: Interface Type
  // generic method 
    public <E> void name (E I) { // generic type parameters do 
        
    }

 

Guess you like

Origin www.cnblogs.com/xuwangqi/p/11221851.html