集册 Java实例教程 使用反射的泛型类中的泛型方法

使用反射的泛型类中的泛型方法

欢马劈雪     最近更新时间:2020-01-02 10:19:05

352
使用反射的泛型类中的泛型方法
/**from 时 代 J a v a**/

import java.util.*;


class ExampleMethods<T> {


    public boolean simpleMethod(String stringParam, int intParam) {

        System.out.println("String: " + stringParam + ", integer: "

                + intParam);

        return true;

    }


    public int varArgsMethod(String... manyStrings) {

        return manyStrings.length;

    }


    public boolean methodWithList(List<String> listParam) {/**时 代 J a v a - N o w J a v a . c o m**/

        return listParam.isEmpty();

    }


    public <T> void genericMethod(T[] a, Collection<T> c) {

        System.out.println("Length of array: " + a.length);

        System.out.println("Size of collection: " + c.size());

    }


}


展开阅读全文