Here you can find the source of toLong(Object obj)
public static Long toLong(Object obj)
//package com.java2s; //License from project: Apache License public class Main { private static final Object NULL = null; public static Long toLong(Object obj) { if (isNull(obj)) { return getNull(); }//from w ww . j a va 2 s . c o m if (obj instanceof Long) { return (Long) obj; } if (obj instanceof Integer || obj instanceof Short || obj instanceof Byte) { return Long.parseLong(obj.toString()); } String objStr = obj.toString(); if (objStr.matches("[-+]?[0-9]+")) { return Long.parseLong(objStr); } return getNull(); } public static boolean isNull(Object obj) { return obj == NULL; } @SuppressWarnings("unchecked") public static <T> T getNull() { return (T) NULL; } }