src/share/classes/java/lang/Long.java

Print this page


   1 /*
   2  * Copyright (c) 1994, 2009, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 686     }
 687 
 688     /**
 689      * Constructs a newly allocated {@code Long} object that
 690      * represents the {@code long} value indicated by the
 691      * {@code String} parameter. The string is converted to a
 692      * {@code long} value in exactly the manner used by the
 693      * {@code parseLong} method for radix 10.
 694      *
 695      * @param      s   the {@code String} to be converted to a
 696      *             {@code Long}.
 697      * @throws     NumberFormatException  if the {@code String} does not
 698      *             contain a parsable {@code long}.
 699      * @see        java.lang.Long#parseLong(java.lang.String, int)
 700      */
 701     public Long(String s) throws NumberFormatException {
 702         this.value = parseLong(s, 10);
 703     }
 704 
 705     /**
 706      * Returns the value of this {@code Long} as a
 707      * {@code byte}.

 708      */
 709     public byte byteValue() {
 710         return (byte)value;
 711     }
 712 
 713     /**
 714      * Returns the value of this {@code Long} as a
 715      * {@code short}.

 716      */
 717     public short shortValue() {
 718         return (short)value;
 719     }
 720 
 721     /**
 722      * Returns the value of this {@code Long} as an
 723      * {@code int}.

 724      */
 725     public int intValue() {
 726         return (int)value;
 727     }
 728 
 729     /**
 730      * Returns the value of this {@code Long} as a
 731      * {@code long} value.
 732      */
 733     public long longValue() {
 734         return (long)value;
 735     }
 736 
 737     /**
 738      * Returns the value of this {@code Long} as a
 739      * {@code float}.

 740      */
 741     public float floatValue() {
 742         return (float)value;
 743     }
 744 
 745     /**
 746      * Returns the value of this {@code Long} as a
 747      * {@code double}.

 748      */
 749     public double doubleValue() {
 750         return (double)value;
 751     }
 752 
 753     /**
 754      * Returns a {@code String} object representing this
 755      * {@code Long}'s value.  The value is converted to signed
 756      * decimal representation and returned as a string, exactly as if
 757      * the {@code long} value were given as an argument to the
 758      * {@link java.lang.Long#toString(long)} method.
 759      *
 760      * @return  a string representation of the value of this object in
 761      *          base 10.
 762      */
 763     public String toString() {
 764         return toString(value);
 765     }
 766 
 767     /**


   1 /*
   2  * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 686     }
 687 
 688     /**
 689      * Constructs a newly allocated {@code Long} object that
 690      * represents the {@code long} value indicated by the
 691      * {@code String} parameter. The string is converted to a
 692      * {@code long} value in exactly the manner used by the
 693      * {@code parseLong} method for radix 10.
 694      *
 695      * @param      s   the {@code String} to be converted to a
 696      *             {@code Long}.
 697      * @throws     NumberFormatException  if the {@code String} does not
 698      *             contain a parsable {@code long}.
 699      * @see        java.lang.Long#parseLong(java.lang.String, int)
 700      */
 701     public Long(String s) throws NumberFormatException {
 702         this.value = parseLong(s, 10);
 703     }
 704 
 705     /**
 706      * Returns the value of this {@code Long} as a {@code byte} after
 707      * a narrowing primitive conversion.
 708      * @jls 5.1.3 Narrowing Primitive Conversions
 709      */
 710     public byte byteValue() {
 711         return (byte)value;
 712     }
 713 
 714     /**
 715      * Returns the value of this {@code Long} as a {@code short} after
 716      * a narrowing primitive conversion.
 717      * @jls 5.1.3 Narrowing Primitive Conversions
 718      */
 719     public short shortValue() {
 720         return (short)value;
 721     }
 722 
 723     /**
 724      * Returns the value of this {@code Long} as an {@code int} after
 725      * a narrowing primitive conversion.
 726      * @jls 5.1.3 Narrowing Primitive Conversions
 727      */
 728     public int intValue() {
 729         return (int)value;
 730     }
 731 
 732     /**
 733      * Returns the value of this {@code Long} as a
 734      * {@code long} value.
 735      */
 736     public long longValue() {
 737         return (long)value;
 738     }
 739 
 740     /**
 741      * Returns the value of this {@code Long} as a {@code float} after
 742      * a widening primitive conversion.
 743      * @jls 5.1.2 Widening Primitive Conversions
 744      */
 745     public float floatValue() {
 746         return (float)value;
 747     }
 748 
 749     /**
 750      * Returns the value of this {@code Long} as a {@code double}
 751      * after a widening primitive conversion.
 752      * @jls 5.1.2 Widening Primitive Conversions
 753      */
 754     public double doubleValue() {
 755         return (double)value;
 756     }
 757 
 758     /**
 759      * Returns a {@code String} object representing this
 760      * {@code Long}'s value.  The value is converted to signed
 761      * decimal representation and returned as a string, exactly as if
 762      * the {@code long} value were given as an argument to the
 763      * {@link java.lang.Long#toString(long)} method.
 764      *
 765      * @return  a string representation of the value of this object in
 766      *          base 10.
 767      */
 768     public String toString() {
 769         return toString(value);
 770     }
 771 
 772     /**