Package snap.util

Class ClassUtils

java.lang.Object
snap.util.ClassUtils

public class ClassUtils extends Object
Utility methods for Class.
  • Constructor Details

    • ClassUtils

      public ClassUtils()
  • Method Details

    • getInstance

      public static <T> T getInstance(Object anObj, Class<T> aClass)
      Returns the given object as instance of given class, if it is.
    • newInstance

      public static <T> T newInstance(Class<T> aClass)
      Returns a new instance of a given class.
    • cloneCloneable

      public static Object cloneCloneable(Cloneable anObj)
      Returns a clone of given Cloneable object using reflection.
    • getClass

      public static Class<?> getClass(Object anObj)
      Returns the class for an object.
    • getMethod

      public static Method getMethod(Class<?> aClass, String aName, Class<?>... theClasses)
      Class.getMethod wrapper to isolate call to one place.
    • getMethodOrThrow

      public static Method getMethodOrThrow(Class<?> aClass, String aName, Class<?>... theClasses) throws NoSuchMethodException
      Class.getMethod wrapper to isolate call to one place.
      Throws:
      NoSuchMethodException
    • toPrimitive

      public static Class<?> toPrimitive(Class<?> aClass)
      Returns primitive type for non-primitive.
    • fromPrimitive

      public static Class<?> fromPrimitive(Class<?> aClass)
      Returns non-primitive type for primitive.
    • getCommonClass

      public static Class<?> getCommonClass(List<?> aList)
      Returns the common ancestor class for a list of objects.
    • getCommonClass

      public static Class<?> getCommonClass(Object anObj1, Object anObj2)
      Returns the common ancestor class for two objects.