Class AccessibleFieldHandler
java.lang.Object
io.github.arasdenizhan.core.handler.AccessibleFieldHandler
Utility class to efficiently retrieve the value of a field via reflection.
Instead of blindly calling setAccessible(true) on each access,
this class first checks if the field is already accessible using canAccess().
If not accessible, it enables access explicitly. This avoids unnecessary reflection overhead.
Note: In some JVM implementations, repeated setAccessible(true) calls are cached,
which can improve performance slightly, though this behavior is not guaranteed in all Java versions.
-
Method Summary
Modifier and TypeMethodDescriptionstatic ObjectgetFieldValue(Field field, Object target) Securely retrieves the value of a field using reflection, enabling access only if necessary.
-
Method Details
-
getFieldValue
Securely retrieves the value of a field using reflection, enabling access only if necessary.- Parameters:
field- The field to read fromtarget- The object instance- Returns:
- The value of the field
- Throws:
IllegalAccessException- if the field is not accessible and cannot be made accessible
-