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

How to use
getConstructors
method
in
java.lang.Class

Best Java code snippets using java.lang.Class.getConstructors (Showing top 20 results out of 11,394)

origin: spring-projects/spring-framework

private static Constructor<?> getEndpointConstructor() {
  for (Constructor<?> current : TyrusEndpointWrapper.class.getConstructors()) {
    Class<?>[] types = current.getParameterTypes();
    if (Endpoint.class == types[0] && EndpointConfig.class == types[1]) {
      return current;
    }
  }
  throw new IllegalStateException("No compatible Tyrus version found");
}
origin: apache/incubator-dubbo

public MapDeserializer(Class type) {
  if (type == null)
    type = HashMap.class;
  _type = type;
  Constructor[] ctors = type.getConstructors();
  for (int i = 0; i < ctors.length; i++) {
    if (ctors[i].getParameterTypes().length == 0)
      _ctor = ctors[i];
  }
  if (_ctor == null) {
    try {
      _ctor = HashMap.class.getConstructor(new Class[0]);
    } catch (Exception e) {
      throw new IllegalStateException(e);
    }
  }
}
origin: prestodb/presto

public static Optional<Constructor<?>> findConstructor(Class<?> clazz)
{
  Constructor<?>[] constructors = clazz.getConstructors();
  checkArgument(constructors.length <= 1, "Class [%s] must have no more than 1 public constructor");
  if (constructors.length == 0) {
    return Optional.empty();
  }
  return Optional.of(constructors[0]);
}
origin: junit-team/junit4

private ParameterSupplier buildParameterSupplierFromClass(
    Class<? extends ParameterSupplier> cls) throws Exception {
  Constructor<?>[] supplierConstructors = cls.getConstructors();
  for (Constructor<?> constructor : supplierConstructors) {
    Class<?>[] parameterTypes = constructor.getParameterTypes();
    if (parameterTypes.length == 1
        && parameterTypes[0].equals(TestClass.class)) {
      return (ParameterSupplier) constructor.newInstance(clazz);
    }
  }
  return cls.newInstance();
}
origin: apache/incubator-dubbo

public static Constructor<?> findConstructor(Class<?> clazz, Class<?> paramType) throws NoSuchMethodException {
  Constructor<?> targetConstructor;
  try {
    targetConstructor = clazz.getConstructor(new Class<?>[]{paramType});
  } catch (NoSuchMethodException e) {
    targetConstructor = null;
    Constructor<?>[] constructors = clazz.getConstructors();
    for (Constructor<?> constructor : constructors) {
      if (Modifier.isPublic(constructor.getModifiers())
          && constructor.getParameterTypes().length == 1
          && constructor.getParameterTypes()[0].isAssignableFrom(paramType)) {
        targetConstructor = constructor;
        break;
      }
    }
    if (targetConstructor == null) {
      throw e;
    }
  }
  return targetConstructor;
}
origin: libgdx/libgdx

/** Returns an array of {@link Constructor} containing the public constructors of the class represented by the supplied Class. */
static public Constructor[] getConstructors (Class c) {
  java.lang.reflect.Constructor[] constructors = c.getConstructors();
  Constructor[] result = new Constructor[constructors.length];
  for (int i = 0, j = constructors.length; i < j; i++) {
    result[i] = new Constructor(constructors[i]);
  }
  return result;
}
origin: libgdx/libgdx

/** Returns an array of {@link Constructor} containing the public constructors of the class represented by the supplied Class. */
static public Constructor[] getConstructors (Class c) {
  java.lang.reflect.Constructor[] constructors = c.getConstructors();
  Constructor[] result = new Constructor[constructors.length];
  for (int i = 0, j = constructors.length; i < j; i++) {
    result[i] = new Constructor(constructors[i]);
  }
  return result;
}
origin: apache/incubator-dubbo

public static Constructor<?> findConstructor(Class<?> clazz, Class<?> paramType) throws NoSuchMethodException {
  Constructor<?> targetConstructor;
  try {
    targetConstructor = clazz.getConstructor(new Class<?>[]{paramType});
  } catch (NoSuchMethodException e) {
    targetConstructor = null;
    Constructor<?>[] constructors = clazz.getConstructors();
    for (Constructor<?> constructor : constructors) {
      if (Modifier.isPublic(constructor.getModifiers())
          && constructor.getParameterTypes().length == 1
          && constructor.getParameterTypes()[0].isAssignableFrom(paramType)) {
        targetConstructor = constructor;
        break;
      }
    }
    if (targetConstructor == null) {
      throw e;
    }
  }
  return targetConstructor;
}
origin: junit-team/junit4

private void validateParameterSupplier(Class<? extends ParameterSupplier> supplierClass, List<Throwable> errors) {
  Constructor<?>[] constructors = supplierClass.getConstructors();
  
  if (constructors.length != 1) {
    errors.add(new Error("ParameterSupplier " + supplierClass.getName() + 
               " must have only one constructor (either empty or taking only a TestClass)"));
  } else {
    Class<?>[] paramTypes = constructors[0].getParameterTypes();
    if (!(paramTypes.length == 0) && !paramTypes[0].equals(TestClass.class)) {
      errors.add(new Error("ParameterSupplier " + supplierClass.getName() + 
                 " constructor must take either nothing or a single TestClass instance"));
    }
  }
}
origin: redisson/redisson

private void readObject(ObjectInputStream in)
  throws IOException, ClassNotFoundException
{
  javaClass = getClassObject(in.readUTF());
  constructors = javaClass.getConstructors();
  methods = null;
}
origin: junit-team/junit4

/**
 * Returns the only public constructor in the class, or throws an {@code
 * AssertionError} if there are more or less than one.
 */
public Constructor<?> getOnlyConstructor() {
  Constructor<?>[] constructors = clazz.getConstructors();
  Assert.assertEquals(1, constructors.length);
  return constructors[0];
}
origin: greenrobot/EventBus

public TestRunner(Context context, TestParams testParams, EventBus controlBus) {
  this.controlBus = controlBus;
  tests = new ArrayList<Test>();
  for (Class<? extends Test> testClazz : testParams.getTestClasses()) {
    try {
      Constructor<?>[] constructors = testClazz.getConstructors();
      Constructor<? extends Test> constructor = testClazz.getConstructor(Context.class, TestParams.class);
      Test test = constructor.newInstance(context, testParams);
      tests.add(test);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }
}
origin: google/j2objc

/**
 * Returns the only public constructor in the class, or throws an {@code
 * AssertionError} if there are more or less than one.
 */
public Constructor<?> getOnlyConstructor() {
  Constructor<?>[] constructors = fClass.getConstructors();
  Assert.assertEquals(1, constructors.length);
  return constructors[0];
}
origin: google/j2objc

  public static AssertionError createArgumentsAreDifferentException(String message, String wanted, String actual)  {
    try {
      Class<?> clazz = Class.forName("org.mockito.exceptions.verification.junit.ArgumentsAreDifferent");
      AssertionError throwable = (AssertionError) clazz.getConstructors()[0].newInstance(message, wanted, actual);
      return throwable;
    } catch (Throwable t) {
//            throw the default exception in case of problems
      return new ArgumentsAreDifferent(message);
    }
  }
}
origin: spring-projects/spring-framework

@Override
@Nullable
public Constructor<?>[] getPreferredConstructors() {
  Class<?> clazz = getBeanClass();
  Constructor<?> primaryCtor = BeanUtils.findPrimaryConstructor(clazz);
  if (primaryCtor != null) {
    return new Constructor<?>[] {primaryCtor};
  }
  Constructor<?>[] publicCtors = clazz.getConstructors();
  if (publicCtors.length > 0) {
    return publicCtors;
  }
  return null;
}
origin: spring-projects/spring-framework

private Mono<?> createAttribute(
    String attributeName, Class<?> clazz, BindingContext context, ServerWebExchange exchange) {
  Constructor<?> ctor = BeanUtils.findPrimaryConstructor(clazz);
  if (ctor == null) {
    Constructor<?>[] ctors = clazz.getConstructors();
    if (ctors.length == 1) {
      ctor = ctors[0];
    }
    else {
      try {
        ctor = clazz.getDeclaredConstructor();
      }
      catch (NoSuchMethodException ex) {
        throw new IllegalStateException("No primary or default constructor found for " + clazz, ex);
      }
    }
  }
  return constructAttribute(ctor, attributeName, context, exchange);
}
origin: google/guava

private static <X extends Exception> X newWithCause(Class<X> exceptionClass, Throwable cause) {
 // getConstructors() guarantees this as long as we don't modify the array.
 @SuppressWarnings({"unchecked", "rawtypes"})
 List<Constructor<X>> constructors = (List) Arrays.asList(exceptionClass.getConstructors());
 for (Constructor<X> constructor : preferringStrings(constructors)) {
  @Nullable X instance = newFromConstructor(constructor, cause);
  if (instance != null) {
   if (instance.getCause() == null) {
    instance.initCause(cause);
   }
   return instance;
  }
 }
 throw new IllegalArgumentException(
   "No appropriate constructor for exception of type "
     + exceptionClass
     + " in response to chained exception",
   cause);
}
origin: weibocom/motan

private void checkConstructorPublic(Class<T> clz) {
  Constructor<?>[] constructors = clz.getConstructors();
  if (constructors == null || constructors.length == 0) {
    failThrows(clz, "Error has no public no-args constructor");
  }
  for (Constructor<?> constructor : constructors) {
    if (Modifier.isPublic(constructor.getModifiers()) && constructor.getParameterTypes().length == 0) {
      return;
    }
  }
  failThrows(clz, "Error has no public no-args constructor");
}
origin: apache/incubator-dubbo

public BeanDeserializer(Class cl) {
  _type = cl;
  _methodMap = getMethodMap(cl);
  _readResolve = getReadResolve(cl);
  Constructor[] constructors = cl.getConstructors();
  int bestLength = Integer.MAX_VALUE;
  for (int i = 0; i < constructors.length; i++) {
    if (constructors[i].getParameterTypes().length < bestLength) {
      _constructor = constructors[i];
      bestLength = _constructor.getParameterTypes().length;
    }
  }
  if (_constructor != null) {
    _constructor.setAccessible(true);
    Class[] params = _constructor.getParameterTypes();
    _constructorArgs = new Object[params.length];
    for (int i = 0; i < params.length; i++) {
      _constructorArgs[i] = getParamArg(params[i]);
    }
  }
}
origin: spring-projects/spring-framework

/**
 * Return the resolved autowire code,
 * (resolving AUTOWIRE_AUTODETECT to AUTOWIRE_CONSTRUCTOR or AUTOWIRE_BY_TYPE).
 * @see #AUTOWIRE_AUTODETECT
 * @see #AUTOWIRE_CONSTRUCTOR
 * @see #AUTOWIRE_BY_TYPE
 */
public int getResolvedAutowireMode() {
  if (this.autowireMode == AUTOWIRE_AUTODETECT) {
    // Work out whether to apply setter autowiring or constructor autowiring.
    // If it has a no-arg constructor it's deemed to be setter autowiring,
    // otherwise we'll try constructor autowiring.
    Constructor<?>[] constructors = getBeanClass().getConstructors();
    for (Constructor<?> constructor : constructors) {
      if (constructor.getParameterCount() == 0) {
        return AUTOWIRE_BY_TYPE;
      }
    }
    return AUTOWIRE_CONSTRUCTOR;
  }
  else {
    return this.autowireMode;
  }
}
java.langClassgetConstructors

Javadoc

Returns an array containing Constructor objects for all public constructors for this Class. If there are no public constructors or if this Class represents an array class, a primitive type or void then an empty array is returned.

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
  • newInstance
    Returns a new instance of the class represented by this Class, created by invoking the default (that
  • 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
  • cast,
  • 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
  • Best IntelliJ plugins
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