Class ClassInstanceUtil


  • public final class ClassInstanceUtil
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <T> T[] createArray​(java.lang.Class<T> theClass, int length)
      Load a class by given name
      <T> java.lang.Class<T> getClassObject​(java.lang.String className)
      Load a class by given name
      static ClassInstanceUtil getInstance()
      Get the instance
      boolean implementsInterface​(java.lang.String className, java.lang.Class<?> interfaceClazz)
      Check if a given class implements an interface
      boolean isClassAvailable​(java.lang.String className)
      Check if the given class exists
      <T> T newInstance​(java.lang.Class<T> clazz)
      Create a new instance of a given class
      <T> T newInstance​(java.lang.String className)
      Create a new instance of a given class
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getInstance

        public static ClassInstanceUtil getInstance()
        Get the instance
        Returns:
        the instance
      • getClassObject

        public <T> java.lang.Class<T> getClassObject​(java.lang.String className)
                                              throws java.lang.ClassNotFoundException
        Load a class by given name
        Type Parameters:
        T - the generic type
        Parameters:
        className - the name of the class
        Returns:
        the loaded class
        Throws:
        java.lang.ClassNotFoundException - in case of error
      • newInstance

        public <T> T newInstance​(java.lang.String className)
                          throws java.lang.ClassNotFoundException,
                                 java.lang.InstantiationException,
                                 java.lang.IllegalAccessException,
                                 java.lang.SecurityException
        Create a new instance of a given class
        Type Parameters:
        T - the generic type
        Parameters:
        className - the name of the class
        Returns:
        the loaded class
        Throws:
        java.lang.ClassNotFoundException - in case of error
        java.lang.InstantiationException - in case of error
        java.lang.IllegalAccessException - in case of error
        java.lang.SecurityException - in case of error
      • newInstance

        public <T> T newInstance​(java.lang.Class<T> clazz)
                          throws java.lang.SecurityException,
                                 java.lang.InstantiationException,
                                 java.lang.IllegalAccessException
        Create a new instance of a given class
        Type Parameters:
        T - the generic type
        Parameters:
        clazz - the class
        Returns:
        the instance
        Throws:
        java.lang.SecurityException - in case of error
        java.lang.reflect.InvocationTargetException - in case of error
        java.lang.IllegalArgumentException - in case of error
        java.lang.IllegalAccessException - in case of error
        java.lang.InstantiationException - in case of error
      • createArray

        public <T> T[] createArray​(java.lang.Class<T> theClass,
                                   int length)
        Load a class by given name
        Type Parameters:
        T - the generic type
        Parameters:
        theClass - the class
        length - the length of the array
        Returns:
        the loaded class
        Throws:
        java.lang.IllegalArgumentException - In case of invalid input
      • isClassAvailable

        public boolean isClassAvailable​(java.lang.String className)
        Check if the given class exists
        Parameters:
        className - the name of the class to check
        Returns:
        true if the class exists; otherwise false
      • implementsInterface

        public boolean implementsInterface​(java.lang.String className,
                                           java.lang.Class<?> interfaceClazz)
        Check if a given class implements an interface
        Parameters:
        className - the class name
        interfaceClazz - the interface
        Returns:
        true if the class implements the interface