Class Reflect

java.lang.Object
one.tranic.t.utils.Reflect

public class Reflect extends Object
Utility class containing reflection-related methods for manipulating and inspecting classes and fields.
  • 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.
      NoSuchFieldException
      IllegalAccessException
    • hasClass

      public static boolean hasClass(@NotNull @NotNull String className)
      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:
      true if the class exists; false otherwise.
    • getClass

      @Nullable public static @Nullable Class<?> getClass(String className)
      Retrieves a Class object associated with the fully qualified name of a class.
      Parameters:
      className - the fully qualified name of the class to retrieve.
      Returns:
      the Class object for the given name, or null if the class cannot be found.