private static < T > T getAnnotationValue ( Annotation annotation , String value , Class < T > expectedType ) { Class < ? extends Annotation > annotationType = annotation . annotationType ( ) ; Method valueMethod ; try { valueMethod = annotationType . getDeclaredMethod ( value ) ; } catch ( NoSuchMethodException e ) { throw new IllegalStateException ( "Cannot resolve required method '" + value + "()' for '" + annotationType + "'." ) ; } Object elementValue ; try { elementValue = valueMethod . invoke ( annotation ) ; } catch ( ReflectiveOperationException e ) { throw new IllegalStateException ( "Cannot invoke method value() for " + annotationType ) ; } return elementValue != null ? expectedType . cast ( elementValue ) : null ; }
Return a value from an annotation .