public static Class < ? > [ ] getClassHierarchy ( Class < ? > type ) { ArrayDeque < Class < ? > > classes = new ArrayDeque < Class < ? > > ( ) ; // class to start our search from, we'll loop thru the entire class hierarchy Class < ? > classType = type ; // keep searching up until we reach an Object class type while ( classType != null && ! classType . equals ( Object . class ) ) { // keep adding onto front classes . addFirst ( classType ) ; classType = classType . getSuperclass ( ) ; } return classes . toArray ( new Class [ 0 ] ) ; }
Returns an array of class objects representing the entire class hierarchy with the most - super class as the first element followed by all subclasses in the order they are declared . This method does not include the generic Object type in its list . If this class represents the Object type this method will return a zero - size array .