public static Field [ ] getDeclaredFieldsInHierarchy ( Class < ? > clazz ) { if ( clazz . isPrimitive ( ) ) { throw new IllegalArgumentException ( "Primitive types not supported." ) ; } List < Field > result = new ArrayList < Field > ( ) ; while ( true ) { if ( clazz == Object . class ) { break ; } result . addAll ( Arrays . asList ( clazz . getDeclaredFields ( ) ) ) ; clazz = clazz . getSuperclass ( ) ; } return result . toArray ( new Field [ result . size ( ) ] ) ; }
Returns an array of all declared fields in the given class and all super - classes .