java.lang.Object
ushiosan.jvm_utilities.lang.reflection.FieldUtils

public final class FieldUtils extends Object
  • Method Details

    • findField

      public static Field findField(@NotNull @NotNull Class<?> cls, @NotNull @NotNull String field) throws NoSuchFieldException
      It searches inside a class (also inside the classes it inherits) and identifies the one that is mentioned inside the parameters of the method. Java handles fields independently for each class, and you cannot access a field that is inside another class, but inherits from it. That is why a trick is performed to perform such a task.
      Parameters:
      cls - the class you want to inspect
      field - the field you want to search for
      Returns:
      the class field you want to access
      Throws:
      NoSuchFieldException - Error if such field does not exist in the entire inheritance tree of the class
    • findFieldObj

      public static Field findFieldObj(@NotNull @NotNull Object obj, @NotNull @NotNull String field) throws NoSuchFieldException
      It searches inside a class (also inside the classes it inherits) and identifies the one that is mentioned inside the parameters of the method. Java handles fields independently for each class, and you cannot access a field that is inside another class, but inherits from it. That is why a trick is performed to perform such a task.
      Parameters:
      obj - the object you want to inspect
      field - the field you want to search for
      Returns:
      the class field you want to access
      Throws:
      NoSuchFieldException - Error if such field does not exist in the entire inheritance tree of the class
    • getAllRecursiveFields

      public static Field @NotNull [] getAllRecursiveFields(@NotNull @NotNull Class<?> cls)
      Returns all defined and undefined fields of a class (for this, this method accesses the inheritance tree to get all these fields)
      Parameters:
      cls - the class you want to inspect
      Returns:
      all valid class fields