public static List < Field > getSelfAndSuperClassFields ( Class < ? > clazz ) { //YongZ added this method List < Field > fields = new ArrayList < Field > ( ) ; for ( Field field : clazz . getDeclaredFields ( ) ) fields . ( field ) ; Class < ? > superclass = clazz . getSuperclass ( ) ; while ( superclass != null ) { if ( Object . class . equals ( superclass ) ) { break ; } for ( Field field : superclass . getDeclaredFields ( ) ) fields . ( field ) ; superclass = superclass . getSuperclass ( ) ; } return fields ; }
Get all fields of a class includes its super class s fields