Java.lang.Class.isEnum() Method

Advertisements


Description

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

Declaration

Following is the declaration for java.lang.Class.isEnum() method

public boolean isEnum()

Parameters

  • NA

Return Value

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

Exception

  • NA

Example

The following example shows the usage of java.lang.Class.isEnum() method.

package com.tutorialspoint;

import java.lang.*;

// enum showing programming languages
enum Language {
   C, Java;
}

public class ClassDemo {

   public static void main(String args[]) {
       
     // returns the name and hashCode of this enum constant
     System.out.print("Programming in " + Language.C.toString());      
     System.out.println(", Hashcode = " + Language.C.hashCode()); 
     System.out.print("Programming in " + Language.Java.toString());  
     System.out.println(", Hashcode = " + Language.Java.hashCode());  
     
     System.out.println(Language.class.isEnum());
   }
} 

Let us compile and run the above program, this will produce the following result:

Programming in C, Hashcode = 1569228633
Programming in Java, Hashcode = 778966024
true



Advertisements
Advertisements