Java Reflection Constructor Get getConstructor(String typeString)

Here you can find the source of getConstructor(String typeString)

Description

get Constructor

License

Open Source License

Declaration

private static <C> Constructor<C> getConstructor(String typeString) throws IllegalArgumentException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.lang.reflect.Constructor;

public class Main {
    private static <C> Constructor<C> getConstructor(String typeString) throws IllegalArgumentException {
        Class<Object> clazz;
        try {//from  w  w w. j a  v  a2 s . c om
            @SuppressWarnings("unchecked")
            Class<Object> clazzCast = (Class<Object>) Class.forName(typeString);
            clazz = clazzCast;
        } catch (ClassNotFoundException e) {
            throw new IllegalArgumentException("Unknown class for type " + typeString);
        }
        try {
            @SuppressWarnings("unchecked")
            Constructor<C> constructor = (Constructor<C>) clazz.getConstructor(new Class[] { String.class });
            return constructor;
        } catch (Exception e) {
            throw new IllegalArgumentException(
                    "Could not find constructor with single String argument for " + clazz);
        }
    }
}

Related

  1. getConstructor(final Class instantiableClass, final Class... classes)
  2. getConstructor(String className, Class... argClasses)
  3. getConstructor(String cls_name, Class[] param_cls)
  4. getConstructor(String string, Class... types)
  5. getConstructor(String type, Class[] paramTypes)
  6. getConstructorAccessor(Class enumClass, Class[] additionalParameterTypes)
  7. getConstructorCalls(Class aClass)
  8. getConstructorDescriptor(final Constructor c)
  9. getConstructorForArguments( java.lang.reflect.Constructor[] constructors, Object... arguments)