Java tutorial
//package com.java2s; import java.lang.reflect.InvocationTargetException; public class Main { static Object getInstanceByClass(Class<?> claz) { try { if (claz == Long.class || claz == Integer.class || claz == Short.class || claz == Double.class || claz == Float.class || claz == Byte.class) return claz.getConstructor(String.class).newInstance("0"); else return claz.newInstance(); } catch (SecurityException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } return null; } }