Online Java Compiler By
JavaTpoint.com
//import statements import java.lang.reflect.Method; public class ReflectMethodgetParameterCountExample2 { public static void method1(int x, int y, double z, String str) {} public static void main(String... args) throws NoSuchMethodException { Method mthd = ReflectMethodgetParameterCountExample2.class.getDeclaredMethod("method1", int.class, int.class, double.class , String.class); //pass classes of types of parameter int paramCount = mthd.getParameterCount(); //get the total no. of parameter System.out.println("No of parameters in method1 : " +paramCount); } }
Output