Online Java Compiler By
JavaTpoint.com
//import statement import java.lang.reflect.Method; //import Method class of lang package public class ReflectMethodgetParameterCountExample1 { public static void proc(int i, String s, String... args) {} public static void main(String... args) throws NoSuchMethodException { //main method Method mthd = ReflectMethodgetParameterCountExample1.class.getDeclaredMethod("proc", int.class, String.class, String[].class); int paramCount = mthd.getParameterCount();//get the total no. of parameter System.out.println(paramCount); //print statemet } }
Output