public static String getFieldNameByType ( Class < ? > classType , Class < ? > fieldType ) { Field [ ] declaredFields = classType . getDeclaredFields ( ) ; for ( Field field : declaredFields ) { if ( field . getType ( ) . isAssignableFrom ( fieldType ) ) { return field . getName ( ) ; } } if ( classType . getSuperclass ( ) != null ) { return getFieldNameByType ( classType . getSuperclass ( ) , fieldType ) ; } return null ; }
Gets the field name by type .