第二阶段31--泛型_泛型方法_泛型方法与可变参数

public class MethodGeneric1 {
    public <T> void method(T...args){
        for(T t:args){
            System.out.println(t);
        }
    }
}
public class Test4 {
    public static void main(String[] args) {
        MethodGeneric1 methodGeneric = new MethodGeneric1();
        String[] arr = new String[]{"a","b","c"};
        Integer[] arr2 = new Integer[]{1,2,3};
        methodGeneric.method(arr);
        methodGeneric.method(arr2);
    }
}

 

posted @ 2022-01-18 14:55  iiuu也一样  阅读(26)  评论(0编辑  收藏  举报