Java Long Number Create toLong(Object object)

Here you can find the source of toLong(Object object)

Description

to Long

License

Open Source License

Declaration

public static Long toLong(Object object) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static Long toLong(Object object) {
        Long longValue;//from   www .  jav  a  2s  . c om
        if (object instanceof String) {
            longValue = (long) Integer.valueOf((String) object);
        } else if (object instanceof Number) {
            // Note: Do *not* use Number.longValue() here, since it causes a GWT exception when in non-hosted mode.
            longValue = (long) ((Number) object).intValue();
        } else if (object == null) {
            longValue = null;
        } else {
            throw new IllegalArgumentException("Failed to convert "
                    + object.getClass().getName() + " [" + object
                    + "] to a Long.");
        }
        return longValue;
    }
}

Related

  1. toLong(Object obj)
  2. toLong(Object obj)
  3. toLong(Object obj)
  4. toLong(Object obj, String pattern)
  5. toLong(Object object)
  6. toLong(Object object)
  7. toLong(Object object)
  8. toLong(Object object, Long defaultValue)
  9. toLong(Object object, long defaultValue)