[] Generic class

Package com.yjf.esupplier.common.test; 

/ ** 
 * @author Shusheng 
 * @description 
 * @email [email protected] 
 * @date 2018/12/13 14:46 
 * / 
public  class ObjectToolDemoTwo {
     / ** 
     * generic classes: 
     * the generic class defined in the 
     * format: public class name of the class <generic type 1, ...> 
     * Note: reference type must be a generic type 
     * / 
    public  static  void main (String [] args) { 
        ObjectToolTwo <String> OT = new new ObjectToolTwo <String> (); 
        ot.setObj ( "Feng Qingyang" ); 
        String S = ot.getObj();
        System.out.println("姓名是:" + s);

        ObjectToolTwo<Integer> ot2 = new ObjectToolTwo<Integer>();
        ot2.setObj(27);
        Integer i = ot2.getObj();
        System.out.println("姓名是:" + i);
    }

}

class ObjectToolTwo<T> {
    private T obj;

    public T getObj() {
        return obj;
    }

    public void setObj(T obj) {
        this.obj = obj;
    }
}

 

Guess you like

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