Java examples for Reflection:Class
Method to check if a Class is a Collection or not.
//package com.book2s; import java.util.*; public class Main { public static void main(String[] argv) { Class c = String.class; System.out.println(isClassCollection(c)); }/*from ww w .ja va 2 s. c om*/ /** * 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); } }