get Constructor by its parameter type - Android java.lang.reflect

Android examples for java.lang.reflect:Constructor

Description

get Constructor by its parameter type

Demo Code


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

public class Main {
    public static Constructor<?> getConstructor(Class<?> targetClass,
            Class<?>... types) {
        if (targetClass == null || types == null)
            return null;
        try {/*from w w  w  .  ja  va2  s.co  m*/
            return targetClass.getConstructor(types);
        } catch (SecurityException e) {
            // ignore
        } catch (NoSuchMethodException e) {
            // ignore
        }
        return null;
    }
}

Related Tutorials