泛型方法的定义与使用

泛型方法的使用:方法中的参数可以接收任意类型的参数

public classObjectTool {  

    public voidshow(T t){

        System.out.println(t);

    }

}

 

public classObjectToolDemo {

 

    public static void main(String[] args) {

        // TODO Auto-generated method stub

 

        ObjectToolot = new ObjectTool();

        ot.show("张三");

        ot.show(27);

        ot.show(true);

       

    }

}

运行结果:

张三

27

true

你可能感兴趣的:(java,集合)