public static Number newInteger ( int type , long value ) { switch ( type ) { case BOOL : case CHAR : case INT : return new Integer ( ( int ) value ) ; case FLOAT : if ( ( long ) ( float ) value == value ) { return new Float ( ( float ) value ) ; } // else fall through: case DOUBLE : if ( ( long ) ( double ) value == value ) { return new Double ( ( double ) value ) ; } // else fall through: case LONG : return new Long ( value ) ; case BYTE : return new Byte ( ( byte ) value ) ; case SHORT : return new Short ( ( short ) value ) ; default : return BigInteger . valueOf ( value ) ; } }
Returns a new Number object of an appropriate type to hold the given integer value . The type of the returned object is consistent with the given type argument which is a constant from the NumericTypes interface .