Class ClassUtils


  • public class ClassUtils
    extends Object
    Allows checking if a class can be assigned to a variable from another class. Code extracted from from Apache Commons Lang 3 - ClassUtils.java
    • Method Detail

      • isAssignable

        public static boolean isAssignable​(Class<?> cls,
                                           Class<?> toClass)
        Checks if one cls can be assigned to a variable of another toClass, like: Cls c = ...; ToClass x = c;
        Parameters:
        cls - the Class to check, may be null
        toClass - the Class to try to assign into, returns false if null
        Returns:
        true if assignment possible
      • primitiveToWrapper

        public static Class<?> primitiveToWrapper​(Class<?> cls)

        Converts the specified primitive Class object to its corresponding wrapper Class object.

        NOTE: From v2.2, this method handles Void.TYPE, returning Void.TYPE.

        Parameters:
        cls - the class to convert, may be null
        Returns:
        the wrapper class for cls or cls if cls is not a primitive. null if null input.
        Since:
        2.1