Class ReflectionUtil
java.lang.Object
jp.ecuacion.lib.core.util.ReflectionUtil
- Direct Known Subclasses:
ConditionalEmptyValidator, ConditionalNotEmptyValidator, ConstraintViolationBean, GreaterThanOrEqualToValidator, GreaterThanValidator, LessThanOrEqualToValidator, LessThanValidator
Provides utility methods for
java.lang.reflect and other checks.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic FieldObtains a field with any scopes and also searches fields in super classes.protected static ObjectObtains a field value with any scopes and searches fields in super classes.static <A extends Annotation>
Optional<A> searchAnnotationPlacedAtClass(Class<?> classOfTargetInstance, Class<A> annotation) Searches for a class annotation in the argument class and its superClasses.
-
Constructor Details
-
ReflectionUtil
public ReflectionUtil()
-
-
Method Details
-
searchAnnotationPlacedAtClass
public static <A extends Annotation> Optional<A> searchAnnotationPlacedAtClass(Class<?> classOfTargetInstance, Class<A> annotation) Searches for a class annotation in the argument class and its superClasses.The search starts at the argument instance, and if it doesn't have the annotation, It searches the superClass of the instance next.
And if it continues to search the annotation and it reaches to Object.class, it stops to search and returns empty Optional.Search ends when it founds the first annotation. Even if there is another anntation of same class, it ignores and it returns first-found annotation.
-
getValue
Obtains a field value with any scopes and searches fields in super classes.Since Class#getDeclaredField is used in the method, making its scope public causes a spotbugs error.
That's why its scope is protected and when you use it you need to extend this class.Public method jp.ecuacion.lib.core.util.internal.PrivateFieldReadUtil.getFieldValue(String, Object, String) uses reflection to modify a field it gets in its parameter which could increase the accessibility of any class. REFLF_REFLECTION_MAY_INCREASE_ACCESSIBILITY_OF_FIELD -
getField
Obtains a field with any scopes and also searches fields in super classes.- Parameters:
object- classOfTargetInstancefieldName- fieldName- Returns:
Pair<Field, Object>left-hand side is the obtained field, right-hand side is its instance. When you set "dept.name" to fieldName, instance would be "dept".
-