Package ushiosan.jvm

Class UClass


public final class UClass extends UClassValidator
Class containing helper methods for working with objects of type Class
  • Field Details

    • FULL_CLASS_STACK

      public static final int FULL_CLASS_STACK
      Property used to return the entire inheritance stack of a class.
      See Also:
    • ALONE_CLASS_STACK

      public static final int ALONE_CLASS_STACK
      Property used to return only the current class from the inheritance stack.
      See Also:
  • Method Details

    • isPrimitive

      public static boolean isPrimitive(@NotNull @NotNull Class<?> cls)
      Checks whether the class of the argument is of some primitive type or some wrapper class corresponding to the primitive type.
      Parameters:
      cls - the class to inspect
      Returns:
      true if the class is a primitive type or false otherwise
    • isPrimitive

      public static boolean isPrimitive(@Nullable @Nullable Object obj)
      Checks whether the class of the argument is of some primitive type or some wrapper class corresponding to the primitive type.
      Parameters:
      obj - the object to inspect
      Returns:
      true if the class is a primitive type or false otherwise
    • classStack

      @NotNull public static @NotNull Stack<Class<?>> classStack(@NotNull @NotNull Class<?> cls, int deep)
      Returns the inheritance of a class recursively. In this way, it is possible to know from how many classes a class inherits functionalities. Although it is possible to only obtain a certain number of elements of that inheritance.
      Parameters:
      cls - the class you want to inspect
      deep - the inheritance boundary that you want to traverse. In addition to the limit, there are 2 special cases, which are used for other behavior:
      • Case 0: This case makes the inheritance recursive until reaching the "Object" class, which is the limit of all Java classes.
      • Case 1: This case causes only the current class to be listed and no other.
      Returns:
      a stack with all the inheritance elements of the chosen class
    • classStack

      @NotNull public static @NotNull Stack<Class<?>> classStack(@NotNull @NotNull Class<?> cls)
      Returns the inheritance of a class recursively. In this way, it is possible to know from how many classes a class inherits functionalities. Although it is possible to only obtain a certain number of elements of that inheritance.
      Parameters:
      cls - the class you want to inspect
      Returns:
      a stack with all the inheritance elements of the chosen class
    • isArrayPrimitive

      public static boolean isArrayPrimitive(@NotNull @NotNull Class<?> cls)
      Checks if the class of the argument is of some primitive type or some wrapper class corresponding to the primitive type (version for arrays).
      Parameters:
      cls - the class to inspect
      Returns:
      true if the class is a primitive type or false otherwise
    • isArrayPrimitive

      public static boolean isArrayPrimitive(@Nullable @Nullable Object obj)
      Checks if the class of the argument is of some primitive type or some wrapper class corresponding to the primitive type (version for arrays).
      Parameters:
      obj - the object to inspect
      Returns:
      true if the class is a primitive type or false otherwise
    • getArrayIndividualClass

      @NotNull public static <T> @NotNull Class<T> getArrayIndividualClass(T @NotNull [] array)
      Returns the class of the individual object in an array.

      Example:

      
       String[] array = new String[] {"Hello", "World", "!"};
       Class<?> cls = Cls.getArrayIndividualClass(array);
      
       // Output -> class java.lang.String
       
      Type Parameters:
      T - the class of the data type
      Parameters:
      array - the array you want to identify
      Returns:
      the data type of the elements individually
    • getArrayIndividualClass

      @NotNull public static <T> @NotNull Class<T> getArrayIndividualClass(T @NotNull [] @NotNull [] array)
      Returns the class of the individual object in an array.

      Example:

      
       String[][] array = new String[0][0];
       Class<?> cls = Cls.getArrayIndividualClass(array);
      
       // Output -> class java.lang.String
       
      Type Parameters:
      T - the class of the data type
      Parameters:
      array - the array you want to identify
      Returns:
      the data type of the elements individually
    • getArrayMultipleIndividualClass

      @NotNull public static <T> @NotNull Class<T> getArrayMultipleIndividualClass(@NotNull @NotNull Object array)
      Returns the class of the individual object in an array.

      Example:

      
       String[][][] array = new String[0][0][0]; // or more
       Class<?> cls = Cls.getArrayIndividualClass(array);
      
       // Output -> class java.lang.String
       
      Type Parameters:
      T - the class of the data type
      Parameters:
      array - the array you want to identify
      Returns:
      the data type of the elements individually
    • toVarargTypes

      public static Class<?> @NotNull [] toVarargTypes(Object... args)
      Returns the data type of all passed elements. This method is useful for knowing through reflection which method you want to call.
      Parameters:
      args - the arguments to convert
      Returns:
      an array with all element types