Java Long Number Create toLong(Object objectToConvert)

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

Description

Given an Object of type Integer or Long, converts the Object instance to a Long.

License

Open Source License

Parameter

Parameter Description
Object a parameter

Return

Long

Declaration

public static Long toLong(Object objectToConvert) 

Method Source Code

//package com.java2s;
/*//ww  w  .  j  a  v  a2  s  . com
 * #%L
 * BroadleafCommerce Common Libraries
 * %%
 * Copyright (C) 2009 - 2016 Broadleaf Commerce
 * %%
 * Licensed under the Broadleaf Fair Use License Agreement, Version 1.0
 * (the "Fair Use License" located  at http://license.broadleafcommerce.org/fair_use_license-1.0.txt)
 * unless the restrictions on use therein are violated and require payment to Broadleaf in which case
 * the Broadleaf End User License Agreement (EULA), Version 1.1
 * (the "Commercial License" located at http://license.broadleafcommerce.org/commercial_license-1.1.txt)
 * shall apply.
 * 
 * Alternatively, the Commercial License may be replaced with a mutually agreed upon license (the "Custom License")
 * between you and Broadleaf Commerce. You may not use this file except in compliance with the applicable license.
 * #L%
 */

public class Main {
    /**
     * Given an Object of type Integer or Long, converts the Object instance to a Long.  This will throw a ClassCastException
     * if the past parameter is not either an Integer or a Long.
     * 
     * @param Object
     * @return Long
     */
    public static Long toLong(Object objectToConvert) {
        Long convertedLongValue;
        if (objectToConvert instanceof Integer) {
            convertedLongValue = new Long((Integer) objectToConvert);
        } else {
            convertedLongValue = (Long) objectToConvert;
        }
        return convertedLongValue;
    }
}

Related

  1. toLong(Object object)
  2. toLong(Object object)
  3. toLong(Object object)
  4. toLong(Object object, Long defaultValue)
  5. toLong(Object object, long defaultValue)
  6. toLong(Object objValue)
  7. toLong(Object oid)
  8. toLong(Object property, long defaultValue)
  9. toLong(Object val)