Java Reflection Constructor Get getConstructorWithNoParams(Class clazz)

Here you can find the source of getConstructorWithNoParams(Class clazz)

Description

get Constructor With No Params

License

Open Source License

Declaration

private static Constructor getConstructorWithNoParams(Class clazz) 

Method Source Code


//package com.java2s;
/*//from   ww w .  j  a  v  a2 s . c o m
 * Copyright 2012 Red Hat, Inc. and/or its affiliates.
 *
 * Licensed under the Eclipse Public License version 1.0, available at
 * http://www.eclipse.org/legal/epl-v10.html
 */

import java.lang.reflect.Constructor;

import java.lang.reflect.Modifier;

public class Main {
    private static Constructor getConstructorWithNoParams(Class clazz) {
        for (Constructor constructor : clazz.getConstructors()) {
            if (constructor.getParameterTypes().length == 0) {
                if (Modifier.isPrivate(constructor.getModifiers())
                        || Modifier.isProtected(constructor.getModifiers())) {
                    constructor.setAccessible(true);
                }
                return constructor;
            }
        }
        return null;
    }
}

Related

  1. getConstructorSignatureWithLongTypeNames(Constructor init)
  2. getConstructorSimpleName(Constructor constructor)
  3. getConstructorsOfLength(final Class clazz, final int length)
  4. getConstructorWithArgs(Class clazz, Object... args)
  5. getConstructorWithLeastParametersFromList( ArrayList constructorsFromType)
  6. getConstructorWithReflection(String className, Class... parameterTypes)