public static Set < Class < ? > > getSuperTypes ( Class < ? > c ) { Set < Class < ? > > classes = new HashSet < Class < ? > > ( ) ; for ( Class < ? > clazz : c . getInterfaces ( ) ) { classes . add ( clazz ) ; classes . addAll ( getSuperTypes ( clazz ) ) ; } Class < ? > sup = c . getSuperclass ( ) ; if ( sup != null ) { classes . add ( sup ) ; classes . addAll ( getSuperTypes ( sup ) ) ; } return Collections . unmodifiableSet ( classes ) ; }
Returns all the super types of the given class that is all the classes in which any instance of the given class can be cast into .