Java Reflection Constructor Get getConstructor(final Class clazz, final Class... parameterTypes)

Here you can find the source of getConstructor(final Class clazz, final Class... parameterTypes)

Description

TODO: Documentation

License

Open Source License

Parameter

Parameter Description
E a parameter
clazz a parameter
parameterTypes a parameter

Declaration

public static <E> Optional<Constructor<? extends E>> getConstructor(final Class<? extends E> clazz,
        final Class<?>... parameterTypes) 

Method Source Code


//package com.java2s;
import java.lang.reflect.Constructor;

import java.util.Optional;

public class Main {
    /**//from   w  ww.  j av  a 2 s.co m
     * TODO: Documentation
     * @param <E>
     * @param clazz
     * @param parameterTypes
     * @return
     */
    public static <E> Optional<Constructor<? extends E>> getConstructor(final Class<? extends E> clazz,
            final Class<?>... parameterTypes) {
        try {
            final Constructor<? extends E> c = clazz.getDeclaredConstructor(parameterTypes);
            return Optional.<Constructor<? extends E>>of(c);
        } catch (final Exception e) {
            return Optional.<Constructor<? extends E>>empty();
        }
    }
}

Related

  1. getConstructor(Class instanceType)
  2. getConstructor(Class targetClass, Class... parameterTypes)
  3. getConstructor(Class type, Class... parameterTypes)
  4. getConstructor(Class type, Class[] parameterTypes)
  5. getConstructor(final Class theClass, final Class... parameterTypes)
  6. getConstructor(final Class clazz, final Class[] paramTypes)
  7. getConstructor(final Class valueClass, final Class parameter)
  8. getConstructor(final Class clazz, final Class... parametertypes)
  9. getConstructor(final Class clazz, final Class... parameterTypes)