public static Object [ ] getEnumValues ( Class < ? extends Enum < ? > > clazz ) { Object [ ] enums = clazz . getEnumConstants ( ) ; if ( enums == null ) { Method [ ] mthds = clazz . getDeclaredMethods ( ) ; Method mthd = null ; for ( Method mth : mthds ) { if ( mth . getName ( ) . equals ( "values" ) ) { mthd = mth ; break ; } } if ( mthd != null ) try { enums = ( Object [ ] ) mthd . invoke ( null ) ; } catch ( Throwable e ) { throw new RuntimeException ( e ) ; } } return enums ; }
finds enum values in normal enum classes and in dynamically created ones .