public static Object getFieldValue ( final Field field , final Object instance ) throws CoreRuntimeException { Object value = null ; try { // store current visibility final boolean accessible = field . isAccessible ( ) ; // let it accessible anyway field . setAccessible ( true ) ; // Call this method with right parameters value = field . get ( instance ) ; // Reset default visibility field . setAccessible ( accessible ) ; } catch ( IllegalAccessException | IllegalArgumentException e ) { throw new CoreRuntimeException ( e ) ; } return value ; }
Retrieve an object field even if it has a private or protected visibility .