Package rife.tools

Class ClassUtils

java.lang.Object
rife.tools.ClassUtils

public final class ClassUtils extends Object
The ClassUtils class provides useful utility methods for working with Java classes.
Since:
1.0
  • Method Details

    • resolveTypeVariable

      public static Type resolveTypeVariable(Class<?> context, TypeVariable<?> variable)
      Follows a type variable through the generic hierarchy of a class.

      This method will for instance resolve the T of a supertype to the type argument that the provided class supplies for it, while continuing to follow the resolved type for as long as it is a type variable itself.

      Parameters:
      context - the class whose generic hierarchy provides the type arguments
      variable - the type variable to resolve
      Returns:
      the resolved type; or

      the type variable itself if the hierarchy doesn't provide an argument for it

      Since:
      1.10
      See Also:
    • erasedType

      public static Class<?> erasedType(Class<?> context, Type type)
      Erases a generic type to the class that it will be at runtime.

      This method will resolve type variables through the generic hierarchy of the provided class, while a variable that can't be resolved erases to its first bound and a wildcard to its upper bound.

      Parameters:
      context - the class whose generic hierarchy provides the type arguments
      type - the generic type to erase
      Returns:
      the erased class; or

      Object if the type can't be erased to anything more specific

      Since:
      1.10
      See Also:
    • isNumeric

      public static boolean isNumeric(Class klass)
      Returns true if the specified class is numeric.
      Parameters:
      klass - the class to check
      Returns:
      true if the specified class is numeric, false otherwise
      Since:
      1.0
    • isText

      public static boolean isText(Class klass)
      Returns true if the specified class is text.
      Parameters:
      klass - the class to check
      Returns:
      true if the specified class is text, false otherwise
      Since:
      1.0
    • isBasic

      public static boolean isBasic(Class klass)
      Returns true if the specified class is a basic type.
      Parameters:
      klass - the class to check
      Returns:
      true if the specified class is a basic type, false otherwise
      Since:
      1.0
    • isFromJdk

      public static boolean isFromJdk(Class klass)
      Returns true if the specified class is from the JDK.
      Parameters:
      klass - the class to check
      Returns:
      true if the specified class is from the JDK, false otherwise
      Since:
      1.0
    • simpleClassName

      public static String simpleClassName(Class klass)
      Returns the simple name of the specified class without the package name.
      Parameters:
      klass - the class whose simple name to return
      Returns:
      the simple name of the specified class
      Since:
      1.0
    • shortenClassName

      public static String shortenClassName(Class klass)
      Returns a shortened version of the specified class name, with "$" characters replaced by underscores.
      Parameters:
      klass - the class whose name to shorten
      Returns:
      a shortened version of the specified class name
      Since:
      1.0
    • getEnumClassValues

      public static String[] getEnumClassValues(Class klass)
      Returns an array of the values of the enum constants of the specified class, or null if the class is not an enum.
      Parameters:
      klass - the class whose enum constant values to return
      Returns:
      an array of the values of the enum constants of the specified class, or null if the class is not an enum
      Since:
      1.0