java.lang.reflect.Method Class in Java Last Updated : 10 Mar, 2021 Comments Improve Suggest changes Like Article Like Report java.lang.reflect.Method class provides necessary details about one method on a certain category or interface and provides access for the same. The reflected method could also be a category method or an instance method (including an abstract method). This class allows broadening of conversions to occur when matching the actual parameters to call the underlying method's formal parameters, but if narrowing conversion would occur, it throws an IllegalArgumentException. java.lang.Object java.lang.reflect.AccessibleObject java.lang.reflect.Executable java.lang.reflect.Method Methods: MethodDescriptionequals(Object obj)This method compares this Method against the specified object.getAnnotatedReturnType()This method returns an Annotated Type object that represents the use of a type to specify the return type of the method/constructor represented by this Executable.getAnnotation(Class<T> annotationClass)This method returns this element's annotation for the specified type if such an annotation is present, else null.getDeclaredAnnotations()This method returns annotations that are directly present on this element.getDeclaringClass()This method returns the Class object representing the class or interface that declares the executable represented by this object.getDefaultValue()This method returns the default value for the annotation member represented by this Method instance.getExceptionTypes()This method returns an array of Class objects that represent the types of exceptions declared to be thrown by the underlying executable represented by this object.getGenericExceptionTypes()This method returns an array of Type objects that represent the exceptions declared to be thrown by this executable object.getGenericParameterTypes()This method returns an array of Type objects that represent the formal parameter types, in declaration order, of the executable represented by this object.getGenericReturnType()This method returns a Type object that represents the formal return type of the method represented by this Method object.getModifiers()This method returns the Java language modifiers for the executable represented by this object.getName()This method returns the name of the method represented by this Method object, as a String.getParameterAnnotations()This method returns an array of arrays of Annotations that represent the annotations on the formal parameters, in declaration order, of the Executable represented by this object.getParameterCount()This method returns the number of formal parameters (whether explicitly declared or implicitly declared or neither) for the executable represented by this object.getParameterTypes()This method returns an array of Class objects that represent the formal parameter types, in declaration order, of the executable represented by this object.getDefaultValue() Method: Java // Java program to show the // Implementation of getDefaultvalue() import java.lang.reflect.Method; public class getDefaultValueExample { public static void main(String[] args) { Method[] methods = Demo.class.getMethods(); // calling method getDefaultValue() System.out.println(methods[0].getDefaultValue()); } } class Demo { private String str; // member function returning string str public String getSampleField() { return str; } public void setSampleField(String str) { this.str = str; } } OutputnulltoString() Method: Java // Java program to show the // Implementation of toString() import java.lang.reflect.Method; public class MethodDemo { public static void main(String[] args) { Method[] methods = SampleClass.class.getMethods(); // calling method toString() System.out.println(methods[1].toString()); } } class SampleClass { private String str; public String getSampleField() { return str; } public void setSampleField(String str) { this.str = str; } } Outputpublic void SampleClass.setSampleField(java.lang.String) Comment More infoAdvertise with us Next Article java.lang.reflect.Method Class in Java M mayanktyagi1709 Follow Improve Article Tags : Java Technical Scripter Technical Scripter 2020 java-lang-reflect-package Practice Tags : Java Similar Reads java.lang.reflect.Modifier Class in Java The java.lang.reflect.Modifier class contains methods used to get information about class, member and method access modifiers. The modifiers are represented as int value with set bits at distinct positions. The int value represents different modifiers. These values are taken from the tables in secti 7 min read java.lang.reflect.Parameter Class in Java java.lang.reflect.Parameter class provides Information about method parameters, including their name and modifiers. It also provides an alternate means of obtaining attributes for the parameter. Some useful methods of Parameter class are: public int getModifiers(): It returns the modifier flags for 4 min read java.lang.reflect.Proxy Class in Java A proxy class is present in java.lang package. A proxy class has certain methods which are used for creating dynamic proxy classes and instances, and all the classes created by those methods act as subclasses for this proxy class. Class declaration: public class Proxy extends Object implements Seria 4 min read java.lang.MethodType Class in Java MethodType is a Class that belongs to java.lang package. This class consists of various types of methods that help in most of cases to find the method type based on the input object, or parameters of the method. All the instances of methodType are immutable. This means the objects of the methodType 4 min read java.lang.reflect.Field Class in Java The ability of the software to analyze itself is known as Reflection. This is provided by the java.lang.reflect package and elements in Class .Field serves the same purpose as the whole reflection mechanism, analyze a software component and describe its capabilities dynamically, at run time rather t 5 min read Like