Constructor newInstance - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Constructor newInstance method.

This code example shows how to use the following methods:newInstance
 
        if (stringConstructor != null)
        { 
            try 
            { 
                s = stringConstructor.newInstance(0, c.length, c);
            } 
            catch (Exception e)
            { 
                // Swallowing as we'll just use a copying constructor 
            } 
        } 
        return s == null ? new String(c) : s;
    } 
 
    /** 
     * Used to get access to protected/private constructor of the specified class 
     * @param klass - name of the class 
     * @param paramTypes - types of the constructor parameters 
     * @return Constructor if successful, null if the constructor cannot be 
9
CodeRank
This code example shows how to use the following methods:newInstance
This code example shows how to use the following methods:newInstance
    } 
 
    @Override 
    public ManagedReference getReference() { 
        try { 
            return new ImmediateManagedReference(constructor.newInstance());
        } catch (Exception e) {
            throw new RuntimeException(e);
        } 
    } 
 
} 
9
CodeRank
This code example shows how to use the following methods:newInstance
		} 
	} 
 
	public ClassLoader getThrowawayClassLoader() {
		try { 
			ClassLoader loader = cloneConstructor.newInstance(getClassLoader());
			// clear out the transformers (copied as well) 
			List<?> list = (List<?>) transformerList.get(loader);
			list.clear();
			return loader;
		} 
		catch (InvocationTargetException ex) {
			throw new IllegalStateException("WebSphere CompoundClassLoader constructor failed", ex.getCause());
		} 
		catch (Exception ex) {
			throw new IllegalStateException("Could not construct WebSphere CompoundClassLoader", ex);
		} 
	} 
 
} 
8
CodeRank
This code example shows how to use the following methods:newInstance
            editor.setAsText(text);
            return editor.getValue();
        } else { 
            try { 
                final Constructor<?> constructor = type.getConstructor(String.class);
                return constructor.newInstance(text);
            } catch (NoSuchMethodException e) {
            } catch (Exception e) {
                e.printStackTrace();
            } 
        } 
 
        return null; 
    } 
 
    public Method getMethod() {
        return method;
    } 
 
    static { 
9
CodeRank
This code example shows how to use the following methods:newInstance
	public ClassLoader getThrowawayClassLoader() {
		try { 
			Object classFinder = this.getClassFinderMethod.invoke(this.classLoader);
			Object parent = this.getParentMethod.invoke(this.classLoader);
			// arguments for 'clone'-like method 
			return (ClassLoader) this.wlGenericClassLoaderConstructor.newInstance(classFinder, parent);
		} 
		catch (InvocationTargetException ex) {
			throw new IllegalStateException("WebLogic GenericClassLoader constructor failed", ex.getCause());
		} 
		catch (Exception ex) {
			throw new IllegalStateException("Could not construct WebLogic GenericClassLoader", ex);
		} 
	} 
} 
8
CodeRank
This code example shows how to use the following methods:setAccessible, newInstance
    /** 
     * Returns an instance of T, constructed using this constructor, with the 
     * supplied arguments. 
     */ 
    public T newInstance(Object[] args) throws Throwable {
        constructor.setAccessible(true);
        try { 
            return constructor.newInstance(args);
        } catch (InvocationTargetException e) {
            throw e.getCause();
        } 
    } 
 
    @Override 
    public String toString() {
        return constructor.toString();
    } 
} 
8
CodeRank
This code example shows how to use the following methods:newInstance
    String pid, Class<? extends ResourceCalculatorProcessTree> clazz, Configuration conf) {
 
    if (clazz != null) {
      try { 
        Constructor <? extends ResourceCalculatorProcessTree> c = clazz.getConstructor(String.class);
        ResourceCalculatorProcessTree rctree = c.newInstance(pid);
        rctree.setConf(conf);
        return rctree;
      } catch(Exception e) {
        throw new RuntimeException(e);
      } 
    } 
 
    // No class given, try a os specific class 
    if (ProcfsBasedProcessTree.isAvailable()) { 
      return new ProcfsBasedProcessTree(pid);
    } 
    if (WindowsBasedProcessTree.isAvailable()) { 
      return new WindowsBasedProcessTree(pid);
    } 
8
CodeRank
This code example shows how to use the following methods:newInstance
        Preconditions.checkArgument(constructorArgs!=null && classes!=null);
        Preconditions.checkArgument(constructorArgs.length==classes.length);
        try { 
            Class clazz = Class.forName(clazzname);
            Constructor constructor = clazz.getConstructor(classes);
            T instance = (T) constructor.newInstance(constructorArgs);
            return instance;
        } catch (ClassNotFoundException e) {
            throw new IllegalArgumentException("Could not find implementation class: " + clazzname, e);
        } catch (NoSuchMethodException e) {
            throw new IllegalArgumentException("Implementation class does not have required constructor: " + clazzname, e);
        } catch (InstantiationException e) {
            throw new IllegalArgumentException("Could not instantiate implementation: " + clazzname, e);
        } catch (IllegalAccessException e) {
            throw new IllegalArgumentException("Could not instantiate implementation: " + clazzname, e);
        } catch (InvocationTargetException e) {
            throw new IllegalArgumentException("Could not instantiate implementation: " + clazzname, e);
        } catch (ClassCastException e) {
            throw new IllegalArgumentException("Could not instantiate implementation: " + clazzname, e);
        } 
8
CodeRank
This code example shows how to use the following methods:newInstance
                    return adapter.invoke(cf, target, topScope, proxy, method, args);
                } 
            }; 
        Object proxy;
        try { 
            proxy = c.newInstance(handler);
        } catch (InvocationTargetException ex) {
            throw Context.throwAsScriptRuntimeEx(ex);
        } catch (IllegalAccessException ex) {
            // Should not happen 
            throw Kit.initCause(new IllegalStateException(), ex);
        } catch (InstantiationException ex) {
            // Should not happen 
            throw Kit.initCause(new IllegalStateException(), ex);
        } 
        return proxy;
    } 
 
    @Override 
    protected boolean isVarArgs(Member member) {
8
CodeRank

Related Constructor newInstance Questions & Answers:

newInstance Method Overview
Uses the constructor represented by this Constructor object to create and initialize a new instance of the constructor's declaring class, with the specified initialization parameters.
See Code Examples for other Java 8 Constructor Methods: