Field isSynthetic() method in Java with Examples
The isSynthetic() method of java.lang.reflect.Field is used to check whether Field Object is a synthetic field or not. If the field is a synthetic field then the function returns true otherwise it will return false.
Synthetic Construct: Synthetic Construct is Class, Fields, and Methods that are created by the Java compiler for internal purposes.
Syntax:
public boolean isSynthetic()
Parameters: This method accepts accepts nothing.
Return: This method returns true if and only if this field is a synthetic field as defined by the Java Language Specification.
Below programs illustrate isSynthetic() method:
Program 1:
// Java program to illustrate isSynthetic() method import java.lang.reflect.Field; import java.time.Month; public class GFG { public static void main(String[] args) throws Exception { // Get field object Field field = Numbers.class.getField("value"); // check field is synthetic or not System.out.println( "The Field is isSynthetic: " + field.isSynthetic()); } } // sample Numbers class class Numbers { // static short value public static long value = 3114256; } |
The Field is isSynthetic: false
Program 2:
// Java program to illustrate isSynthetic() method import java.lang.reflect.Field; import java.time.DayOfWeek; public class GFG { public static void main(String[] args) throws Exception { // Get field object of Month class Field[] fields = DayOfWeek.class .getDeclaredFields(); for (int i = 0; i < fields.length; i++) { // print name of Fields System.out.println( "The Field " + fields[i].toString() + "\n is isSynthetic:" + fields[i].isSynthetic()); } } } |
The Field public static final java.time.DayOfWeek java.time.DayOfWeek.MONDAY
is isSynthetic:false
The Field public static final java.time.DayOfWeek java.time.DayOfWeek.TUESDAY
is isSynthetic:false
The Field public static final java.time.DayOfWeek java.time.DayOfWeek.WEDNESDAY
is isSynthetic:false
The Field public static final java.time.DayOfWeek java.time.DayOfWeek.THURSDAY
is isSynthetic:false
The Field public static final java.time.DayOfWeek java.time.DayOfWeek.FRIDAY
is isSynthetic:false
The Field public static final java.time.DayOfWeek java.time.DayOfWeek.SATURDAY
is isSynthetic:false
The Field public static final java.time.DayOfWeek java.time.DayOfWeek.SUNDAY
is isSynthetic:false
The Field private static final java.time.DayOfWeek[] java.time.DayOfWeek.ENUMS
is isSynthetic:false
The Field private static final java.time.DayOfWeek[] java.time.DayOfWeek.$VALUES
is isSynthetic:true
References: https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Field.html#isSynthetic–java
Recommended Posts:
- Class isSynthetic() method in Java with Examples
- Constructor isSynthetic() method in Java with Examples
- Field get() method in Java with Examples
- Field set() method in Java with Examples
- Field isEnumConstant() method in Java with Examples
- Field getGenericType() method in Java with Examples
- Field setInt() method in Java with Examples
- Field getDeclaringClass() method in Java with Examples
- Field equals() method in Java with Examples
- Field getModifiers() method in Java with Examples
- Field getDeclaredAnnotations() method in Java With Examples
- Field setDouble() method in Java with Examples
- Field toGenericString() method in Java with Examples
- Field setShort() method in Java with Examples
- Field setChar() method in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.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.

