public static String getConstantName ( Object value , Class c ) { for ( Field f : c . getDeclaredFields ( ) ) { int mod = f . getModifiers ( ) ; if ( Modifier . isStatic ( mod ) && Modifier . isPublic ( mod ) && Modifier . isFinal ( mod ) ) { try { if ( f . get ( null ) . equals ( value ) ) { return f . getName ( ) ; } } catch ( IllegalAccessException e ) { return String . valueOf ( value ) ; } } } return String . valueOf ( value ) ; }
Gets user - friendly name of the public static final constant defined in a class or an interface for display purpose .