Create an instance of a primitive type using reflection

You have to use the appropriate wrapper classes that are associated with the primitive types:

   boolean    java.lang.Boolean 
   char       java.lang.Character 
   byte       java.lang.Byte 
   short      java.lang.Short 
   int        java.lang.Integer 
   long       java.lang.Long 
   float      java.lang.Float 
   double     java.lang.Double 

This example shows you how to go about creating a Boolean wrapper and converting it to its corresponding primitive type.

Main.java:

import java.lang.reflect.*;
 
public class Main {
   public static void main(String args[]) {
      try {
         Constructor c = Boolean.class.getConstructor(new Class[] { boolean.class });
         Boolean b = (Boolean) c.newInstance(new Object[] { new Boolean(true) });
 
         boolean result = b.booleanValue();
         System.out.println(result);
      }
      catch(NoSuchMethodException e) {
         System.err.println(e);
      }
      catch(InvocationTargetException e) {
         System.err.println(e);
      }
      catch(InstantiationException e) { 
         System.err.println(e);
      }
      catch(IllegalAccessException e) { 
         System.err.println(e);
      }
   }
}