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
- Field isSynthetic() method in Java with Examples
- Method Class | getReturnType() Method in Java
- Method Class | getParameterTypes() Method in Java
- Method Class | getModifiers() method in Java
- Method Class | getDeclaringClass() method in Java
- Method Class | getDeclaredAnnotations() method in Java
- Method Class | toGenericString() method in Java
- Method Class | getParameterCount() method in Java
- Method Class | getAnnotation() method in Java
- Method Class | isVarArgs() Method in Java
- Method Class | getGenericReturnType() Method in Java
- Method Class | isBridge() Method in Java
- Method Class | getDefaultValue() Method in Java
- Method Class | isDefault() Method in Java
- Method Class | getGenericExceptionTypes() 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 firstname.lastname@example.org. 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.