Code example for Constructor

Methods: getDeclaringClass, newInstance

0
 */ 
public class ObjectFactoryImpl implements IObjectFactory { 
   
  public Object newInstance(Constructor constructor, Object... params) {
    try { 
      return constructor.newInstance(params);
    } 
    catch (IllegalAccessException ex) {
      return ClassHelper.tryOtherConstructor(constructor.getDeclaringClass());
    } 
    catch (InstantiationException ex) {
      return ClassHelper.tryOtherConstructor(constructor.getDeclaringClass());
    } 
    catch(Exception ex) {
      throw new TestNGException("Cannot instantiate class " 
          + constructor.getDeclaringClass().getName(), ex);
    } 
  } 
}