Java Reflection - 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 . j  a v  a2s  . com

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.