Here you can find the source of intToBasicType(int i, Class
@SuppressWarnings("unchecked") public static <T> T intToBasicType(int i, Class<T> clazz)
//package com.java2s; //License from project: LGPL public class Main { @SuppressWarnings("unchecked") public static <T> T intToBasicType(int i, Class<T> clazz) { if (clazz.equals(Boolean.class)) return (T) Boolean.valueOf(intToBoolean(i)); if (clazz.equals(Byte.class)) return (T) intToByte(i); if (clazz.equals(Character.class)) return (T) intToCharacter(i); if (clazz.equals(Short.class)) return (T) intToShort(i); if (clazz.equals(Integer.class)) return (T) Integer.valueOf(i); if (clazz.equals(Long.class)) return (T) Long.valueOf(i); if (clazz.equals(Float.class)) return (T) Float.valueOf(i); if (clazz.equals(Double.class)) return (T) Double.valueOf(i); return null; }//from w w w.ja v a 2 s .c o m public static boolean intToBoolean(int i) { return i != 0 ? true : false; } public static Byte intToByte(int i) { if (i >= Byte.MIN_VALUE && i <= Byte.MAX_VALUE) { return (byte) i; } return null; } public static byte intToByte(int i, byte defaultValue) { if (i >= Byte.MIN_VALUE && i <= Byte.MAX_VALUE) { return (byte) i; } return defaultValue; } public static Character intToCharacter(int i) { if (i >= Character.MIN_VALUE && i <= Character.MAX_VALUE) { return (char) i; } return null; } public static Short intToShort(int i) { if (i >= Short.MIN_VALUE && i <= Short.MAX_VALUE) { return (short) i; } return null; } public static short intToShort(int i, short defaultValue) { if (i >= Short.MIN_VALUE && i <= Short.MAX_VALUE) { return (short) i; } return defaultValue; } }