[Generic method]

Package com.yjf.esupplier.common.test; 

/ ** 
 * @author Shusheng 
 * @description 
 * @email [email protected] 
 * @date 2018/12/13 14:46 
 * / 
public  class ObjectToolDemoThree {
     / ** 
     * generic method: 
     * defined in the generic method 
     * format: public <generic type> return type name (generic type.) 
     * method parameters may receive any type of parameters, and regardless of the type of the class 
     * / 
    public  static  void main (String [] args) { 

        ObjectToolThree OTT = new new ObjectToolThree (); 
        ott.show ( "Feng Qingyang" ); 
        ott.show ( 27 );
        ott.show(true);
    }

}

class ObjectToolThree {

    public <T> void show(T t) {
        System.out.println(t);
    }

}

 

Guess you like

Origin www.cnblogs.com/zuixinxian/p/11275037.html