Method Class | getGenericParameterTypes() method in Java Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report The java.lang.reflect.Method.getGenericParameterTypes() method of Method class returns an array of Type objects that represent the parameter types, declared in method at time of coding. It means that the getGenericParameterTypes() method returns array of parameters that belongs to method object. It returns an array of length 0 if the method object takes no parameters. If a formal parameter type is a parameterized type, the Type object returned for it must accurately reflect the actual type parameters used in the source code. e.g for method public void getValue(T value){} substitute a type parameter T with a parameterized type (i.e., List) then method will return "java.util.List" as parameter type. Syntax: public Type[] getGenericParameterTypes() Return Value: This method returns an array of Types that represent the formal parameter types of the method object, in declaration order. Exception: This method throws following exceptions: GenericSignatureFormatError - if the generic method signature is not same as the format specified in The JVM Specification. TypeNotPresentException - if parameter types refers to a non-existent type declaration. MalformedParameterizedTypeException - if the underlying parameter types refers to a parameterized type that cannot be instantiated for any reason. Below programs illustrates getGenericParameterTypes() method of Method class: Program 1: Print all Parameter type declared for Method Java // Program Demonstrate how to apply getGenericParameterTypes() method // of Method Class. import java.lang.reflect.Method; import java.lang.reflect.Type; public class GFG { // Main method public static void main(String[] args) { try { // create class object Class classobj = demoClass.class; // get Method Object Method[] methods = classobj.getMethods(); // iterate through methods for (Method method : methods) { // only taking method defined in the demo class if (method.getName().equals("setValue") || method.getName().equals("getValue") || method.getName().equals("setManyValues")) { // apply getGenericParameterTypes() method Type[] parameters = method.getGenericParameterTypes(); // print parameter Types of method Object System.out.println("\nMethod Name : " + method.getName()); System.out.println("No of Parameters : " + parameters.length); System.out.println("Parameter object details:"); for (Type type : parameters) { System.out.println(type.getTypeName()); } } } } catch (Exception e) { e.printStackTrace(); } } } // a simple class class demoClass { // method containing two parameter public void setValue(String value1, String value2) { System.out.println("setValue"); } // method containing no parameter public String getValue() { System.out.println("getValue"); return "getValue"; } // method containing many parameter public void setManyValues(int value1, double value2, String value3) { System.out.println("setManyValues"); } } Output: Method Name : setManyValues No of Parameters : 3 Parameter object details: int double java.lang.String Method Name : getValue No of Parameters : 0 Parameter object details: Method Name : setValue No of Parameters : 2 Parameter object details: java.lang.String java.lang.String Program 2: Check if the Method object contains parameter or not Java // Program Demonstrate how to apply getGenericParameterTypes() // method of Method Class. import java.lang.reflect.Method; import java.lang.reflect.Type; public class GFG { // Main method public static void main(String[] args) { try { // create class object Class classobj = sample.class; Method[] methods = classobj.getMethods(); /*check whether setManyValues() method contains int parameter or not and print no of string parameter it contains*/ for (Method method : methods) { if (method.getName().equals("setValue")) { int count = containsParameter( method, (Type)java.lang.String.class); System.out.println("No of String" + " Parameters in setValue(): " + count); } } // check whether setManyValues() method // contains int parameter or not // and print no of string parameter it contains for (Method method : methods) { if (method.getName().equals("setManyValues")) { int count = containsParameter(method, (Type) int.class); System.out.println("No of int Parameters" + " in setManyValues(): " + count); } } } catch (Exception e) { e.printStackTrace(); } } // count no of parameters contain by // method same as passed to method private static int containsParameter(Method method, Type parameterName) { int count = 0; // get all parameter types list // using getGenericParameterTypes() Type parameters[] = method.getGenericParameterTypes(); for (int i = 0; i < parameters.length; i++) { // check contains parameter or not if (parameters[i] == parameterName) { count++; } } return count; } } // a simple class class sample { // method containing two parameter public void setValue(String value1, String value2) { System.out.println("setValue"); } // method containing many parameter public void setManyValues(int value1, double value2, String value3) { System.out.println("setManyValues"); } } Output: No of String Parameters in setValue(): 2 No of int Parameters in setManyValues(): 1 Reference: https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Method.html#getGenericParameterTypes-- Comment More infoAdvertise with us Next Article Method Class | getTypeParameters() Method in Java A AmanSingh2210 Follow Improve Article Tags : Java Java-lang package Java-Functions Java-Method Class java-lang-reflect-package +1 More Practice Tags : Java Similar Reads Method Class | getParameterTypes() Method in Java Prerequisite : Java.lang.Class class in Java | Set 1, Java.lang.Class class in Java | Set 2 java.lang.reflectMethod class help us to get information of a single method on a class or interface. This class also provides access to the methods of classes and invoke them at runtime. getParameterTypes() m 4 min read Method Class | getGenericReturnType() Method in Java The getGenericReturnType() method of java.lang.reflect.Method class returns a Type object that represent the return type, declared in method at time of coding. Hence, getGenericReturnType() method returns the return type of method object. If a formal return type is a parameterized type, the Type obj 4 min read Method Class | getTypeParameters() Method in Java The java.lang.reflect.Method.getTypeParameters() method of Method class returns an array of TypeVariable objects declared by the generic declaration of this Method object, in declaration order. Elements of array represent the type variables objects declared by Method. An array of length 0 is returne 4 min read Method Class | getGenericExceptionTypes() Method in Java The getGenericExceptionTypes() method of java.lang.reflectMethod class returns an array of Type objects representing Exceptions thrown by the method object to handle exception. All the exceptions handled by method using thrown clause are returned as array of Type objects using this method. This meth 4 min read Method Class | getParameterCount() method in Java The java.lang.reflect.Method.getParameterCount() method of Method class returns the number of parameters declared on a method Object. Syntax: public int getParameterCount() Return Value: This method returns number of formal parameters defined on this Method Object. Below programs illustrates getPara 3 min read Method Class | getReturnType() Method in Java Prerequisite : Java.lang.Class class in Java | Set 1, Java.lang.Class class in Java | Set 2The java.lang.reflectMethod Class help in getting information of a single method on a class or interface. This class also provides access to the methods of classes and invoke them at runtime. The getReturnType 4 min read Like