Java.lang Package Classes

Java Class - isEnum() Method



The java.lang.Class.isEnum() method returns true if and only if this class was declared as an enum in the source code.

Syntax

public boolean isEnum()

Parameters

No parameter is required.

Return Value

Returns true if and only if this class was declared as an enum in the source code.

Exception

NA.

Example:

In the example below, the java.lang.Class.isEnum() method is used to check whether the given class is declared as an enum in the source code or not.

import java.lang.*;

public class MyClass {

  //creating an enum
  public enum weekday{
    MON, TUE, WED, THU, FRI
  }

  public static void main(String[] args) {
    //get class of weekday and check if it is
    //declared as an enum in the source code
    Class cls = weekday.class;
    System.out.println("Is weekday an enum?: " + cls.isEnum());
  }
}

The output of the above code will be:

Is weekday an enum?: true

❮ Java.lang - Class