Java Class.isPrimitive()

Syntax

Class.isPrimitive() has the following syntax.

public boolean isPrimitive()

Example

In the following code shows how to use Class.isPrimitive() method.


//from w  w  w  .jav a  2  s  . c o  m

public class Main {

   public static void main(String[] args) {
     Main cl = new Main();
     Class c1Class = cl.getClass();

     // returns the Class object associated with an integer
     int k = 5;
     Class kClass = int.class;

     boolean retval1 = c1Class.isPrimitive();
     System.out.println(retval1);

     boolean retval2 = kClass.isPrimitive();
     System.out.println(retval2);
   }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable