Tabnine Logo
Class.newInstance
Code IndexAdd Tabnine to your IDE (free)

How to use
newInstance
method
in
java.lang.Class

Best Java code snippets using java.lang.Class.newInstance (Showing top 20 results out of 93,933)

origin: greenrobot/EventBus

@Override
public SubscriberInfo getSuperSubscriberInfo() {
  if(superSubscriberInfoClass == null) {
    return null;
  }
  try {
    return superSubscriberInfoClass.newInstance();
  } catch (InstantiationException e) {
    throw new RuntimeException(e);
  } catch (IllegalAccessException e) {
    throw new RuntimeException(e);
  }
}
origin: spring-projects/spring-framework

  @Override
  public Object run() throws Exception {
    return cl.newInstance();
  }
}, acc);
origin: apache/incubator-dubbo

public static Object newInstance(String name) {
  try {
    return forName(name).newInstance();
  } catch (InstantiationException e) {
    throw new IllegalStateException(e.getMessage(), e);
  } catch (IllegalAccessException e) {
    throw new IllegalStateException(e.getMessage(), e);
  }
}
origin: apache/incubator-dubbo

protected Object instantiate()
  throws Exception {
  try {
    if (_constructor != null)
      return _constructor.newInstance(_constructorArgs);
    else
      return _type.newInstance();
  } catch (Exception e) {
    throw new HessianProtocolException("'" + _type.getName() + "' could not be instantiated", e);
  }
}
origin: apache/incubator-dubbo

public static Object newInstance(String name) {
  try {
    return forName(name).newInstance();
  } catch (InstantiationException e) {
    throw new IllegalStateException(e.getMessage(), e);
  } catch (IllegalAccessException e) {
    throw new IllegalStateException(e.getMessage(), e);
  }
}
origin: alibaba/druid

public void setStatLoggerClassName(String className) {
  Class<?> clazz;
  try {
    clazz = Class.forName(className);
    DruidDataSourceStatLogger statLogger = (DruidDataSourceStatLogger) clazz.newInstance();
    this.setStatLogger(statLogger);
  } catch (Exception e) {
    throw new IllegalArgumentException(className, e);
  }
}
origin: apache/incubator-dubbo

@SuppressWarnings("unchecked")
private T createAdaptiveExtension() {
  try {
    return injectExtension((T) getAdaptiveExtensionClass().newInstance());
  } catch (Exception e) {
    throw new IllegalStateException("Can't create adaptive extension " + type + ", cause: " + e.getMessage(), e);
  }
}
origin: apache/incubator-dubbo

@SuppressWarnings("unchecked")
private T createAdaptiveExtension() {
  try {
    return injectExtension((T) getAdaptiveExtensionClass().newInstance());
  } catch (Exception e) {
    throw new IllegalStateException("Can't create adaptive extension " + type + ", cause: " + e.getMessage(), e);
  }
}
origin: iluwatar/java-design-patterns

private Command getCommand(String request) {
 Class<?> commandClass = getCommandClass(request);
 try {
  return (Command) commandClass.newInstance();
 } catch (Exception e) {
  throw new ApplicationException(e);
 }
}
origin: libgdx/libgdx

  public static GdxTest newTest (String testName) {
    testName = originalToObfuscated.get(testName, testName);
    try {
      return forName(testName).newInstance();
    } catch (InstantiationException e) {
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      e.printStackTrace();
    }
    return null;
  }
}
origin: libgdx/libgdx

/** Creates a new instance of the class represented by the supplied Class. */
static public <T> T newInstance (Class<T> c) throws ReflectionException {
  try {
    return c.newInstance();
  } catch (InstantiationException e) {
    throw new ReflectionException("Could not instantiate instance of class: " + c.getName(), e);
  } catch (IllegalAccessException e) {
    throw new ReflectionException("Could not instantiate instance of class: " + c.getName(), e);
  }
}
 
origin: spring-projects/spring-framework

  @Bean
  @Lazy
  public Object notLoadable() throws Exception {
    return Class.forName("does.not.exist").newInstance();
  }
}
origin: alibaba/fastjson

public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
  PropertyProcessable processable;
  try {
    processable = this.type.newInstance();
  } catch (Exception e) {
    throw new JSONException("craete instance error");
  }
  Object object =parser.parse(processable, fieldName);
  return (T) object;
}
origin: alibaba/druid

public void setPasswordCallbackClassName(String passwordCallbackClassName) throws Exception {
  Class<?> clazz = Utils.loadClass(passwordCallbackClassName);
  if (clazz != null) {
    this.passwordCallback = (PasswordCallback) clazz.newInstance();
  } else {
    LOG.error("load passwordCallback error : " + passwordCallbackClassName);
    this.passwordCallback = null;
  }
}
origin: alibaba/druid

public void setValidConnectionCheckerClassName(String validConnectionCheckerClass) throws Exception {
  Class<?> clazz = Utils.loadClass(validConnectionCheckerClass);
  ValidConnectionChecker validConnectionChecker = null;
  if (clazz != null) {
    validConnectionChecker = (ValidConnectionChecker) clazz.newInstance();
    this.validConnectionChecker = validConnectionChecker;
  } else {
    LOG.error("load validConnectionCheckerClass error : " + validConnectionCheckerClass);
  }
}
origin: google/guava

private void runTestMethod(ClassLoader classLoader) throws Exception {
 Class<?> test = classLoader.loadClass(FuturesTest.class.getName());
 Object testInstance = test.newInstance();
 test.getMethod("setUp").invoke(testInstance);
 test.getMethod(getName()).invoke(testInstance);
 test.getMethod("tearDown").invoke(testInstance);
}
origin: google/guava

private void runTestMethod(ClassLoader classLoader) throws Exception {
 Class<?> test = classLoader.loadClass(AbstractFutureTest.class.getName());
 test.getMethod(getName()).invoke(test.newInstance());
}
origin: alibaba/druid

public Object createInstance(BeanInfo beanInfo) {
  try {
    return beanInfo.getClazz().newInstance();
  } catch (InstantiationException ex) {
    throw new DruidRuntimeException("create instance error", ex);
  } catch (IllegalAccessException ex) {
    throw new DruidRuntimeException("create instance error", ex);
  }
}
origin: skylot/jadx

private void makeInstance() throws Exception {
  String fullName = clsNode.getFullName();
  instance = getClassLoader().loadClass(fullName).newInstance();
  if (instance == null) {
    throw new NullPointerException("Instantiation failed");
  }
}
origin: spring-projects/spring-framework

@Test
public void testManualProxyJavaWithStaticPointcutAndTwoClassLoaders() throws Exception {
  LogUserAdvice logAdvice = new LogUserAdvice();
  AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
  pointcut.setExpression(String.format("execution(* %s.TestService.*(..))", getClass().getName()));
  // Test with default class loader first...
  testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, new TestServiceImpl(), "TestServiceImpl");
  // Then try again with a different class loader on the target...
  SimpleThrowawayClassLoader loader = new SimpleThrowawayClassLoader(new TestServiceImpl().getClass().getClassLoader());
  // Make sure the interface is loaded from the  parent class loader
  loader.excludeClass(TestService.class.getName());
  loader.excludeClass(TestException.class.getName());
  TestService other = (TestService) loader.loadClass(TestServiceImpl.class.getName()).newInstance();
  testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, other, "TestServiceImpl");
}
java.langClassnewInstance

Javadoc

Returns a new instance of the class represented by this Class, created by invoking the default (that is, zero-argument) constructor. If there is no such constructor, or if the creation fails (either because of a lack of available memory or because an exception is thrown by the constructor), an InstantiationException is thrown. If the default constructor exists but is not accessible from the context where this method is invoked, an IllegalAccessException is thrown.

Popular methods of Class

  • getName
    Returns the name of the class represented by this Class. For a description of the format which is us
  • getSimpleName
  • getClassLoader
  • isAssignableFrom
    Determines if the class or interface represented by this Class object is either the same as, or is a
  • forName
    Returns the Class object associated with the class or interface with the given string name, using th
  • getMethod
    Returns a Method object that reflects the specified public member method of the class or interface r
  • getResourceAsStream
    Finds a resource with a given name. The rules for searching resources associated with a given class
  • getSuperclass
    Returns the Class representing the superclass of the entity (class, interface, primitive type or voi
  • getConstructor
  • cast
    Casts an object to the class or interface represented by this Class object.
  • isInstance
  • getCanonicalName
    Returns the canonical name of the underlying class as defined by the Java Language Specification. Re
  • isInstance,
  • getCanonicalName,
  • getDeclaredField,
  • isArray,
  • getAnnotation,
  • getDeclaredFields,
  • getResource,
  • getDeclaredMethod,
  • getMethods

Popular in Java

  • Making http post requests using okhttp
  • scheduleAtFixedRate (Timer)
  • notifyDataSetChanged (ArrayAdapter)
  • getSharedPreferences (Context)
  • BorderLayout (java.awt)
    A border layout lays out a container, arranging and resizing its components to fit in five regions:
  • Socket (java.net)
    Provides a client-side TCP socket.
  • SecureRandom (java.security)
    This class generates cryptographically secure pseudo-random numbers. It is best to invoke SecureRand
  • Locale (java.util)
    Locale represents a language/country/variant combination. Locales are used to alter the presentatio
  • JFileChooser (javax.swing)
  • Loader (org.hibernate.loader)
    Abstract superclass of object loading (and querying) strategies. This class implements useful common
  • Top plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now