Here you can find the source of toLong(Object o)
public static Long toLong(Object o)
//package com.java2s; //License from project: Open Source License public class Main { /**/* www . j a va 2 s. co m*/ * */ public static Long toLong(Object o) { Long result; if (o == null) { result = null; } else if (o instanceof Number) { Number n = (Number) o; result = n.longValue(); } else { try { result = Long.valueOf(o.toString().trim()); } catch (Exception e) { throw new NumberFormatException("Invalid long: " + o); } } return result; } /** * Safely gets the Long equivalent of a Long value (and throws exception if no * such conversion is possible). */ public static Long toLong(Long l) { if (l == null) { return null; } else { return l.longValue(); } } }