Java Class New Instance newInstance(final Object obj, final String clazz)

Here you can find the source of newInstance(final Object obj, final String clazz)

Description

new Instance

License

Apache License

Declaration

@SuppressWarnings("unchecked")
    public static <R> R newInstance(final Object obj, final String clazz)
            throws ClassNotFoundException, InstantiationException, IllegalAccessException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    @SuppressWarnings("unchecked")
    public static <R> R newInstance(final Object obj, final String clazz)
            throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        final Class<?> c = obj.getClass().getClassLoader().loadClass(clazz);
        return (R) c.newInstance();
    }/*w w  w  .  j a  v a2s . c  o m*/
}

Related

  1. newInstance(final Class clazz)
  2. newInstance(final Class clazz)
  3. newInstance(final Class clazz)
  4. newInstance(final Class type, final int length)
  5. newInstance(final ClassLoader classLoader, final String className, final Object... constructorArgs)
  6. newInstance(final String className, ClassLoader cl)
  7. newInstance(final String className, final Object[] args)
  8. newInstance(final String fullyQualifiedClass)
  9. newInstance(Map> providerMap, String provider, Class[] paramsClass, Object[] paramValues)