Home » Java programming language

Java Class class isSynthetic() method with example

Class class isSynthetic() method: Here, we are going to learn about the isSynthetic() method of Class class with its syntax and example.
Submitted by Preeti Jain, on November 02, 2019

Class class isSynthetic() method

  • isSynthetic() method is available in java.lang package.
  • isSynthetic() method is used to check whether this Class is a synthetic class or not.
  • isSynthetic() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
  • isSynthetic() method does not throw an exception at the time of checking synthetic class.

Syntax:

    public boolean isSynthetic();

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of this method is boolean, it returns a boolean value based on the following cases,

  • It returns true, when this Class is a synthetic class.
  • It returns false, when this Class is not a synthetic class.

Example:

// Java program to demonstrate the example 
// of boolean isSynthetic() method of Class

public class IsSyntheticOfClass {
    public static void main(String[] args) {
        // Create and Return String class
        String str = new String();
        Class cl1 = str.getClass();

        // We are checking the class is a
        // Synthetic class
        boolean b1 = cl1.isPrimitive();

        System.out.print("Is" + " " + cl1.getSimpleName() + " ");
        System.out.println("Synthetic class" + ": " + b1);
    }
}

Output

Is String Synthetic class: false


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.