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.
isSynthetic() method of Method class: This function checks whether Method Object is a synthetic construct or not. If the method is a synthetic construct then the function returns true otherwise it will return false.
Synthetic Construct: Synthetic Construct are Class, Fields, and Methods that are created by the Java compiler for internal purposes.
public boolean isSynthetic()
Return Value: This method returns true if and only if Method is a synthetic construct as specified by the JVM. Else it returns false.
Below programs illustrates isSynthetic() method of Method class:
In below program when the main method creates an object of nested private class Demo and tries to access the private variable name “message”. When it is compiled, it will create a synthetic method. The details of that synthetic method can be obtained by getting the object of that method with the use of isSynthetic() method as shown in below program.
private Message variable of Demo classA Computer Science portal for geeks static java.lang.String GFG$Demo.access$100(GFG$Demo) method is Synthetic Method :true
Example 2: Program to return all the Synthetic construct Methods of BigInteger class.
Explanation: In this Method, at first, BigInteger Class Object is created. After creating Class Object of BigInteger Class, a list of Method Objects is created by calling getMethods() of class Object. Iterate through Method list and get Synthetic Method by checking Method is Synthetic or not using isSynthetic(). At last print Synthetic Method name.
Synthetic Methods of BigInteger Class are Method: compareTo
- Class isSynthetic() method in Java with Examples
- Field isSynthetic() method in Java with Examples
- Constructor isSynthetic() method in Java with Examples
- Method Class | isBridge() Method in Java
- Method Class | getTypeParameters() Method in Java
- Method Class | getParameterTypes() Method in Java
- Method Class | getExceptionTypes() Method in Java
- Method Class | hashCode() Method in Java
- Method Class | getGenericExceptionTypes() Method in Java
- Method Class | getName() Method in Java
- Method Class | getReturnType() Method in Java
- Method Class | getParameterAnnotations() method in Java
- Method Class | getAnnotatedReturnType() method in Java
- Method Class | equals() Method in Java
- Method Class | getParameterCount() method in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.