new a class instance
772014
static Parser<Expression> simpleNewExpression(Parser<Expression> arg, Parser<DefBody> body) {
    return Parsers.sequence(
        term("new").next(TypeLiteralParser.ELEMENT_TYPE_LITERAL),
        argumentList(arg),
        body.optional(),
        (type, args, defBody) -> new NewExpression(null, type, args, defBody));
  }
324534
protected T createInstance() {
		try {
			return targetClass.newInstance();
		} catch (InstantiationException e) {
			throw new RuntimeException(e);
		} catch (IllegalAccessException e) {
			throw new RuntimeException(e);
		}
	}
817146
public static <T> T newInstance(Class<T> aClass)
    {
        try
        {
            return aClass.getConstructor().newInstance();
        }
        catch (InstantiationException e)
        {
            throw new RuntimeException(e);
        }
        catch (IllegalAccessException e)
        {
            throw new RuntimeException(e);
        }
        catch (NoSuchMethodException e)
        {
            throw new RuntimeException(e);
        }
        catch (InvocationTargetException e)
        {
            throw new RuntimeException(e);
        }
    }
149910
def createInstance(self, codec=None):
        
        if type(self.klass) is type:
            return self.klass.__new__(self.klass)

        return self.klass()
694716
public static <T> T newInstance(Class<T> clazz) throws ClassInstantiationException {
        if (clazz == null) {
            return null;
        }

        try {
            return clazz.newInstance();
        } catch (Exception e) {
            throw new ClassInstantiationException("Failed to instantiate class: " + clazz.getName(), e);
        }
    }
892287
public static <T> T newInstance(Class<T> clazz) throws MjdbcException {
        try {
            return clazz.newInstance();

        } catch (InstantiationException ex) {
            throw new MjdbcException(
                    "Failed to create instance: " + clazz.getName() + " - " + ex.getMessage());

        } catch (IllegalAccessException ex) {
            throw new MjdbcException(
                    "Failed to create instance: " + clazz.getName() + " - " + ex.getMessage());
        }
    }
161316
def singleton(cls):
    '''
    
    '''

    cls.__new_original__ = cls.__new__

    @wraps(cls.__new__)
    def singleton_new(cls, *args, **kw):
        it = cls.__dict__.get('__it__')
        if it is not None:
            return it

        cls.__it__ = it = cls.__new_original__(cls, *args, **kw)
        it.__init_original__(*args, **kw)
        return it

    cls.__new__ = singleton_new
    cls.__init_original__ = cls.__init__
    cls.__init__ = object.__init__

    return cls
20557
public static Object newInstanceFromName(Object enclosingObject, String className, ClassLoader classLoader) {
		try {
			Class<?> clazz = Class.forName(className, false, classLoader);
			for (Constructor<?> c : clazz.getConstructors()) {
				Class<?>[] parameterTypes = c.getParameterTypes();
				if (parameterTypes.length == 0) {
					return c.newInstance();
				} else if (parameterTypes.length == 1 && enclosingObject != null && parameterTypes[0].equals(enclosingObject.getClass())) {
					return c.newInstance(enclosingObject);
				}
			}
			return clazz.newInstance();
		} catch (Exception e) {
			String m = "Couldn't create instance from name " + className + " (" + e.getMessage() + ")";
			LOG.error(m, e);
			throw new RuntimeException(m);
		}
	}
901981
public static <T> T newInstance(String className, Object... initargs) 
	throws SetupException
	{
		return newInstance(toClass(className),initargs);		
	}
654946
private static Object newInstance(Class type, Long pipelineId) {
        Constructor _constructor = null;
        Object[] _constructorArgs = new Object[1];
        _constructorArgs[0] = pipelineId;

        try {
            _constructor = type.getConstructor(new Class[] { Long.class });
        } catch (NoSuchMethodException e) {
            throw new ArbitrateException("Constructor_notFound");
        }

        try {
            return _constructor.newInstance(_constructorArgs);
        } catch (Exception e) {
            throw new ArbitrateException("Constructor_newInstance_error", e);
        }

    }
903718
public Object newInstance(String className) {
        try {
            return classLoader.loadClass(className).newInstance();
        } catch (Exception e) {
            throw new ScalaInstanceNotFound(className);
        }
    }
697390
def new(cls, **kwargs):
        
        kwargs = cls.preprocess_kwargs_before_new(kwargs)
        if cls.__mapper__.polymorphic_on is not None:
            discriminator_key = cls.__mapper__.polymorphic_on.name
            discriminator_val = kwargs.get(discriminator_key)
            if discriminator_val is not None and discriminator_val in cls.__mapper__.polymorphic_map:
                actual_cls = cls.__mapper__.polymorphic_map[discriminator_val].class_
                return actual_cls(
                    **subdict(
                        actual_cls._preprocess_params(kwargs),
                        actual_cls.all_settable_keys())
                )
        return cls(**subdict(cls._preprocess_params(kwargs), cls.all_settable_keys()))
264549
def create_class( name , superclass = nil )
      raise "create_class #{name.class}" unless name.is_a? Symbol
      superclass = :Object unless superclass
      raise "create_class #{superclass.class}" unless superclass.is_a? Symbol
      type = get_type_by_class_name(superclass)
      c = Class.new(name , superclass , type )
      classes[name] = c
    end
660926
@SuppressWarnings("unchecked")
  public static <T> T newInstance(Class<T> theClass, Configuration conf) {
    return newInstance(theClass, conf, true);
  }
646613
public T newInstance(Object... args) throws Throwable
    {
        Constructor<? extends T> constructor = ClassUtils.findBestTypedConstructor(klass, args);
        return ClassUtils.invoke(constructor, args);
    }
572628
public static <T> T newInstance(Constructor<T> constructor, Object... args) throws IllegalAccessException, InvocationTargetException, InstantiationException {
        if (constructor.isVarArgs()) {
            args = fixVarArgs(constructor.getParameterTypes(), args);
        }
        return constructor.newInstance(args);
    }
557243
@SuppressWarnings("unchecked")
	public static <T> T newInstance(Class<?> aClass) 
	{
		if(aClass == null)
			return null;
		
				try
				{
					if(String.class.equals(aClass))
					{
						return (T)"";
					}
					else if(Integer.class.equals(aClass))
					{
						return (T)Integer.valueOf(0);
					}
					else if(Date.class.equals(aClass))
					{
						return (T)Calendar.getInstance().getTime();
					}				
					else if(Long.class.equals(aClass) ||
							long.class.equals(aClass))
					{
						return (T)Long.valueOf(0);
					}		
					else if(Character.class.equals(aClass) ||
							char.class.equals(aClass) )
					{
						return (T) Character.valueOf('\0');
					}
					else if(Float.class.equals(aClass) ||
							float.class.equals(aClass))
					{
						return (T)Float.valueOf(0);
					}
					else if(Double.class.equals(aClass) || 
						   double.class.equals(aClass))
					{
						return (T)Double.valueOf(0);
					}				
					
					Constructor<T> constructor = (Constructor<T>)aClass.getDeclaredConstructor();
					
					
					return (T)constructor.newInstance();
					
				}
				catch(IllegalAccessException e)
				{
					throw new SetupException("Trying to create "+aClass.getName()+" "+e.getMessage());
				}
				catch(NoSuchMethodException | InvocationTargetException | InstantiationException e)
				{
						//Get constructor
						Constructor<?>[] constructors = aClass.getConstructors();
							
						int len = constructors.length;
						for(int i=0; i < len; i++)
						{
							Class<?>[] parameterTypes = constructors[i].getParameterTypes();
						    
							if(parameterTypes == null || parameterTypes.length == 0)
								throw new SetupException("Trying to create "+aClass.getName()+" "+e.getMessage()); //has a default constructor but not able to create it
							
							//Construct arguments
							Object[] initargs = new Object[parameterTypes.length];
							
							for(int argsIndex=0; argsIndex <  initargs.length;argsIndex++)
							{
								initargs[argsIndex] = newInstance(parameterTypes[argsIndex]);
							}
							
							try
							{
								return (T)constructors[i].newInstance(initargs);
							}
							catch(Exception exception)
							{}
						}//end for constructors
						
						//not able to success use another constructor
						throw new SetupException("Trying to create class with name:"+aClass.getName()+" ERROR:"+e.getMessage());	
					}//end catch
			}