Java.lang Package Classes

Java Class - isSynthetic() Method



The java.lang.Class.isSynthetic() method returns true if this class is a synthetic class; returns false otherwise.

Syntax

public boolean isSynthetic()

Parameters

No parameter is required.

Return Value

Returns true if and only if this class is a synthetic class as defined by the Java Language Specification.

Exception

NA.

Example:

In the example below, the java.lang.Class.isSynthetic() method is used to check if the given class is a synthetic class or not.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    MyClass x = new MyClass();
    Class cls = x.getClass();

    //print the name of the class
    String name = cls.getName();
    System.out.println("Class Name: " + name);

    //check if the class is a synthetic class
    Boolean result = cls.isSynthetic();
    System.out.println("Is it Synthetic Class?: " + result);
  }
}

The output of the above code will be:

Class Name: MyClass
Is it Synthetic Class?: false

❮ Java.lang - Class