Package one.tranic.t.utils
Class Reflect
java.lang.Object
one.tranic.t.utils.Reflect
Utility class containing reflection-related methods for manipulating and inspecting classes and fields.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidassignToStaticFieldIfUninitialized(@NotNull Class<?> targetClass, @NotNull String fieldName, @NotNull Object value) Assigns a value to a static field in the specified class if the field is currently uninitialized (null).static @Nullable Class<?>Retrieves aClassobject associated with the fully qualified name of a class.static booleanChecks whether a class with the specified fully qualified name exists in the classpath.
-
Constructor Details
-
Reflect
public Reflect()
-
-
Method Details
-
assignToStaticFieldIfUninitialized
public static void assignToStaticFieldIfUninitialized(@NotNull @NotNull Class<?> targetClass, @NotNull @NotNull String fieldName, @NotNull @NotNull Object value) throws NoSuchFieldException, IllegalAccessException Assigns a value to a static field in the specified class if the field is currently uninitialized (null).- Parameters:
targetClass- the class containing the static field.fieldName- the name of the static field to assign the value to.value- the value to assign to the static field if uninitialized.- Throws:
IllegalArgumentException- if the specified field is not static.RuntimeException- if the field cannot be accessed or assigned.NoSuchFieldExceptionIllegalAccessException
-
hasClass
Checks whether a class with the specified fully qualified name exists in the classpath.- Parameters:
className- the fully qualified name of the class to check.- Returns:
trueif the class exists;falseotherwise.
-
getClass
Retrieves aClassobject associated with the fully qualified name of a class.- Parameters:
className- the fully qualified name of the class to retrieve.- Returns:
- the
Classobject for the given name, ornullif the class cannot be found.
-