Package org.objenesis.instantiator

Examples of org.objenesis.instantiator.ObjectInstantiator


  protected ObjectInstantiator newInstantiator (final Class type) {
    if (!Util.isAndroid) {
      // ReflectASM.
      try {
        final ConstructorAccess access = ConstructorAccess.get(type);
        return new ObjectInstantiator() {
          public Object newInstance () {
            try {
              return access.newInstance();
            } catch (Exception ex) {
              throw new KryoException("Error constructing instance of class: " + className(type), ex);
            }
          }
        };
      } catch (Exception ignored) {
      }
    }
    // Reflection.
    try {
      Constructor ctor;
      try {
        ctor = type.getConstructor((Class[])null);
      } catch (Exception ex) {
        ctor = type.getDeclaredConstructor((Class[])null);
        ctor.setAccessible(true);
      }
      final Constructor constructor = ctor;
      return new ObjectInstantiator() {
        public Object newInstance () {
          try {
            return constructor.newInstance();
          } catch (Exception ex) {
            throw new KryoException("Error constructing instance of class: " + className(type), ex);
View Full Code Here


  /** Creates a new instance of a class using {@link Registration#getInstantiator()}. If the registration's instantiator is null,
   * a new one is set using {@link #newInstantiator(Class)}. */
  public <T> T newInstance (Class<T> type) {
    Registration registration = getRegistration(type);
    ObjectInstantiator instantiator = registration.getInstantiator();
    if (instantiator == null) {
      instantiator = newInstantiator(type);
      registration.setInstantiator(instantiator);
    }
    return (T)instantiator.newInstance();
  }
View Full Code Here

  protected ObjectInstantiator newInstantiator (final Class type) {
    if (!Util.isAndroid) {
      // ReflectASM.
      try {
        final ConstructorAccess access = ConstructorAccess.get(type);
        return new ObjectInstantiator() {
          public Object newInstance () {
            try {
              return access.newInstance();
            } catch (Exception ex) {
              throw new KryoException("Error constructing instance of class: " + className(type), ex);
            }
          }
        };
      } catch (Exception ignored) {
      }
    }
    // Reflection.
    try {
      Constructor ctor;
      try {
        ctor = type.getConstructor((Class[])null);
      } catch (Exception ex) {
        ctor = type.getDeclaredConstructor((Class[])null);
        ctor.setAccessible(true);
      }
      final Constructor constructor = ctor;
      return new ObjectInstantiator() {
        public Object newInstance () {
          try {
            return constructor.newInstance();
          } catch (Exception ex) {
            throw new KryoException("Error constructing instance of class: " + className(type), ex);
View Full Code Here

  /** Creates a new instance of a class using {@link Registration#getInstantiator()}. If the registration's instantiator is null,
   * a new one is set using {@link #newInstantiator(Class)}. */
  public <T> T newInstance (Class<T> type) {
    Registration registration = getRegistration(type);
    ObjectInstantiator instantiator = registration.getInstantiator();
    if (instantiator == null) {
      instantiator = newInstantiator(type);
      registration.setInstantiator(instantiator);
    }
    return (T)instantiator.newInstance();
  }
View Full Code Here

TOP

Related Classes of org.objenesis.instantiator.ObjectInstantiator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.