Creating instances Constructor Checker

Implement checkPublicParameterlessConstructor that returns true if the provided class declares public parameterless constructor and false otherwise.

/**
 * Check whether the class declares public parameterless constructor
 */
class ConstructorChecker {

    public boolean checkPublicParameterlessConstructor(Class<?> clazz) {
        try {
            clazz.getConstructor();
            return true;
        } catch (NoSuchMethodException e) {
            return false;
        }
    }

}
posted @ 2020-09-14 14:23  longlong6296  阅读(126)  评论(0)    收藏  举报