private void resetEnumRelatedState ( ) { if ( clazz == null ) { // the reloadabletype exists but the class hasn't been loaded yet! return ; } try { Field f = clazz . getClass ( ) . getDeclaredField ( "enumConstants" ) ; f . setAccessible ( true ) ; f . set ( clazz , null ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } try { Field f = clazz . getClass ( ) . getDeclaredField ( "enumConstantDirectory" ) ; f . setAccessible ( true ) ; f . set ( clazz , null ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } }
When an enum type is reloaded two caches need to be cleared out from the Class object for the enum type .