Here you can find the source of longToBasicType(long l, Class
@SuppressWarnings("unchecked") public static <T> T longToBasicType(long l, Class<T> clazz)
//package com.java2s; //License from project: LGPL public class Main { @SuppressWarnings("unchecked") public static <T> T longToBasicType(long l, Class<T> clazz) { if (clazz.equals(Boolean.class)) return (T) Boolean.valueOf(longToBoolean(l)); if (clazz.equals(Byte.class)) return (T) longToByte(l); if (clazz.equals(Character.class)) return (T) longToCharacter(l); if (clazz.equals(Short.class)) return (T) longToShort(l); if (clazz.equals(Integer.class)) return (T) longToInteger(l); if (clazz.equals(Long.class)) return (T) Long.valueOf(l); if (clazz.equals(Float.class)) return (T) Float.valueOf(l); if (clazz.equals(Double.class)) return (T) Double.valueOf(l); if (clazz.equals(String.class)) return (T) String.valueOf(l); return null; }/*from w w w . j av a2s . co m*/ public static boolean longToBoolean(long l) { return l != 0 ? true : false; } public static Byte longToByte(long l) { if (l >= Byte.MIN_VALUE && l <= Byte.MAX_VALUE) { return (byte) l; } return null; } public static byte longToByte(long l, byte defaultValue) { if (l >= Byte.MIN_VALUE && l <= Byte.MAX_VALUE) { return (byte) l; } return defaultValue; } public static Character longToCharacter(long l) { if (l >= Character.MIN_VALUE && l <= Character.MAX_VALUE) { return (char) l; } return null; } public static Short longToShort(long l) { if (l >= Short.MIN_VALUE && l <= Short.MAX_VALUE) { return (short) l; } return null; } public static short longToShort(long l, short defaultValue) { if (l >= Short.MIN_VALUE && l <= Short.MAX_VALUE) { return (short) l; } return defaultValue; } public static Integer longToInteger(long l) { if (l >= Integer.MIN_VALUE && l <= Integer.MAX_VALUE) { return (int) l; } return null; } }