Following methods of Class class is used to determine the Type of class object:

1) public boolean isInterface(): determines if the specified Class object represents an interface type.

2) public boolean isArray(): determines if this Class object represents an array class.

3) public boolean isPrimitive(): determines if the specified Class object represents a primitive type.


Let's see the simple example of reflection api to determine the object type.
drag_handle
interface B {
}

enum Week {
}

class Test {
	public static void main(String[] args) throws ClassNotFoundException {

		Class c2 = Class.forName("B");
		Class c3 = Class.forName("Week");
		if (c2.isInterface()) {
			System.out.println("B is interface =>" + c2.isInterface());
		} else {
			System.out.println("B is not a interface");
		}

		if (c3.isEnum()) {
			System.out.println("Week is Enum =>" + c3.isEnum());
		} else {
			System.out.println("Week is not a Enum");
		}
	}
}

Output:

B is interface =>true
Week is Enum =>true

What next?

Share this page