public static Object instantiate(Class implementedOrExtendedClass,Class clazz) throws ClassInstantiationException {
  if (!JavaClassHelper.isSubclassOrImplementsInterface(clazz,implementedOrExtendedClass)) {
    if (implementedOrExtendedClass.isInterface()) {
      throw new ClassInstantiationException("Class '" + clazz.getName() + "' does not implement interface '"+ implementedOrExtendedClass.getName()+ "'");
    }
    throw new ClassInstantiationException("Class '" + clazz.getName() + "' does not extend '"+ implementedOrExtendedClass.getName()+ "'");
  }
  Object obj;
  try {
    obj=clazz.newInstance();
  }
 catch (  InstantiationException ex) {
    throw new ClassInstantiationException("Unable to instantiate from class '" + clazz.getName() + "' via default constructor",ex);
  }
catch (  IllegalAccessException ex) {
    throw new ClassInstantiationException("Illegal access when instantiating class '" + clazz.getName() + "' via default constructor",ex);
  }
  return obj;
}

public static Object instantiate ( Class implementedOrExtendedClass , Class clazz ) throws ClassInstantiationException { if ( ! JavaClassHelper . isSubclassOrImplementsInterface ( clazz , implementedOrExtendedClass ) ) { if ( implementedOrExtendedClass . isInterface ( ) ) { throw new ClassInstantiationException ( "Class '" + clazz . getName ( ) + "' does not implement interface '" + implementedOrExtendedClass . getName ( ) + "'" ) ; } throw new ClassInstantiationException ( "Class '" + clazz . getName ( ) + "' does not extend '" + implementedOrExtendedClass . getName ( ) + "'" ) ; } Object obj ; try { obj = clazz . newInstance ( ) ; } catch ( InstantiationException ex ) { throw new ClassInstantiationException ( "Unable to instantiate from class '" + clazz . getName ( ) + "' via default constructor" , ex ) ; } catch ( IllegalAccessException ex ) { throw new ClassInstantiationException ( "Illegal access when instantiating class '" + clazz . getName ( ) + "' via default constructor" , ex ) ; } return obj ; }
checks that the given class implements or extends the required interface ( first parameter ) , and instantiates an object .
