has Default Constructor - Java Reflection

Java examples for Reflection:Constructor

Description

has Default Constructor

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        Class clazz = String.class;
        System.out.println(hasDefaultConstructor(clazz));
    }/*from  w  w w.j av  a  2 s . co m*/

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

Related Tutorials