tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Java > Reflection > Get Class Type

Get Class Type 

The following example shows how to verify whether the given class is an interface, enum or class. Class provides the following APIs,

public boolean isInterface()
 - Returns true if the class object is an interface otherwise false.

public boolean isEnum()
 - Returns true if the class object is an enum type otherwise false.

File Name  :  
Author  :  Sudhakar KV
Email  :  [email protected]
package com.bethecoder.tutorials.reflection;

import java.util.Stack;

public class GetClassType {

  enum ServerStatus {
   @param args
  public static void main(String[] args) {
  private static void checkClassOrInterface(Class<?> clazz) {
    if (clazz.isInterface()) {
      System.out.println(clazz + " is an Interface.");
    else if (clazz.isEnum()) {
      System.out.println(clazz + " is an Enum.");
    else {
      System.out.println(clazz + " is a Class.");


It gives the following output,
class java.lang.String is a Class.
class java.util.Stack is a Class.

interface java.lang.Runnable is an Interface.
interface is an Interface.

class java.lang.Thread$State is an Enum.
class com.bethecoder.tutorials.reflection.GetClassType$ServerStatus is an Enum.


bl  br