检查一个类是否是集合

import java.util.*;

public class Main {
    public static void main(String[] argv) {
        Class c = String.class;
        System.out.println(isClassCollection(c));
    }

    /**
     * Method to check if a Class is a Collection or not.
     * @param c the Class to inspect.
     * @return if true the class extend or implememnt Collection.
     */
    public static boolean isClassCollection(Class c) {
        return Collection.class.isAssignableFrom(c)
                || Map.class.isAssignableFrom(c);
    }
}

你可能感兴趣的:(检查一个类是否是集合)