Class ClassUtil

java.lang.Object
org.moddingx.libx.util.ClassUtil

public class ClassUtil extends Object
Utilities for instances of the Class class.
  • Constructor Details

    • ClassUtil

      public ClassUtil()
  • Method Details

    • boxed

      public static Class<?> boxed(Class<?> cls)
      Returns the given class unless it's a primitive class in which case the boxed class for that primitive is returned.
    • unboxed

      public static Class<?> unboxed(Class<?> cls)
      Returns the given class unless it's a boxed primitive class in which case the primitive class for that boxed class is returned.
    • forName

      @Nullable public static Class<?> forName(String cls)
      Same as Class.forName(String) but instead of throwing a ClassNotFoundException, returns null.
    • callerClass

      @Nullable public static Class<?> callerClass(int level)
      Gets the caller class for method call, the given amount of stack frames up. This skips reflection frames.
      Parameters:
      level - How many stack frames this should go up. 0 means the method that called callerClass(int). 1 is the class that called the method from which callerClass(int) was invoked.