Java Reflection Constructor Get getConstructorsOfLength(final Class clazz, final int length)

Here you can find the source of getConstructorsOfLength(final Class clazz, final int length)

Description

get Constructors Of Length

License

Apache License

Declaration

public static List<Constructor> getConstructorsOfLength(final Class clazz, final int length) 

Method Source Code


//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License");

import java.lang.reflect.Constructor;

import java.lang.reflect.Modifier;
import java.util.ArrayList;

import java.util.List;

public class Main {
    public static List<Constructor> getConstructorsOfLength(final Class clazz, final int length) {
        List<Constructor> fixedLengthConstructors = new ArrayList<Constructor>(1);

        Constructor[] constructors = clazz.getDeclaredConstructors();

        for (int i = 0; i < constructors.length; i++) {
            if (!Modifier.isPublic(constructors[i].getModifiers()))
                continue;

            Class[] parameterTypes = constructors[i].getParameterTypes();

            if (parameterTypes.length == length)
                fixedLengthConstructors.add(constructors[i]);
        }/*w  w w.j av a  2s  . c  om*/

        return fixedLengthConstructors;
    }
}

Related

  1. getConstructors(Class clazz, int modifier)
  2. getConstructors(final Class cl, final int params)
  3. getConstructorSignature(final Constructor constructor)
  4. getConstructorSignatureWithLongTypeNames(Constructor init)
  5. getConstructorSimpleName(Constructor constructor)
  6. getConstructorWithArgs(Class clazz, Object... args)
  7. getConstructorWithLeastParametersFromList( ArrayList constructorsFromType)
  8. getConstructorWithNoParams(Class clazz)
  9. getConstructorWithReflection(String className, Class... parameterTypes)