Java Reflection Java Java API
java.lang.reflect.Method
public int getParameterCount()
Returns the number of formal parameters (whether explicitly declared or implicitly declared or neither) for the method represented by this object.
package com.logicbig.example.method;import java.lang.reflect.Method;public class GetParameterCountExample { public static void process(int i, String s, String... args) {} public static void main(String... args) throws NoSuchMethodException { Method m = GetParameterCountExample.class .getDeclaredMethod("process", int.class, String.class, String[].class); int parameterCount = m.getParameterCount(); System.out.println(parameterCount); }}
3