has Constructor - Java Reflection

Java examples for Reflection:Constructor

Description

has Constructor

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        Class clazz = String.class;
        Class paramType = String.class;
        System.out.println(hasConstructor(clazz, paramType));
    }/*w w w . jav  a  2  s .  c  o  m*/

    public static boolean hasConstructor(Class clazz, Class paramType) {
        try {
            clazz.getConstructor(new Class[] { paramType });
            return true;
        } catch (NoSuchMethodException ex) {
            return false;
        }
    }
}

Related Tutorials