日期:2014-05-20 浏览次数:20821 次
public class Test { public static void main(String[] args) { List<Class<? extends A>> list = new ArrayList<Class<? extends A>>(); list.add(A.class); list.add(C.class); list.add(B.class); Class<? extends A> cls = findOuterClass(list); System.out.println(cls); } public static <T> Class<? extends T> findOuterClass(List<Class<? extends T>> list) { if (list == null || list.size() == 0) return null; Class<? extends T> outerClass = list.get(0); for (int i=0; i<list.size(); ) { try { Class<? extends T> cls = list.get(i); cls = outerClass.asSubclass(cls); i++; } catch (Exception e) { outerClass = list.get(i); } } return outerClass; } } class A { } class B extends A { } class C extends B { }