Close

Java Reflection - Class.isPrimitive() Examples

Code Snippets Java Reflection Java 


Class:

java.lang.Class

java.lang.Objectjava.lang.Objectjava.lang.Classjava.lang.Classjava.io.SerializableSerializablejava.lang.reflect.GenericDeclarationGenericDeclarationjava.lang.reflect.TypeTypejava.lang.reflect.AnnotatedElementAnnotatedElementLogicBig

Method:

public boolean isPrimitive()

Returns true if and only if this class represents a primitive type.


Examples


package com.logicbig.example.clazz;

public class IsPrimitiveExample {

public static void main(String... args) {
boolean b = int.class.isPrimitive();
System.out.println(b);

b = int[].class.isPrimitive();
System.out.println(b);

b = Integer.class.isPrimitive();
System.out.println(b);
}
}

Output

true
false
false




package com.logicbig.example.clazz;

public class IsPrimitiveExample2 {

public static void main(String... args) {
boolean b = void.class.isPrimitive();
System.out.println(b);

b = Void.class.isPrimitive();
System.out.println(b);
}
}

Output

true
false




See Also