src/share/classes/java/lang/Short.java

Print this page


   1 /*
   2  * Copyright (c) 1996, 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


 304     }
 305 
 306     /**
 307      * Constructs a newly allocated {@code Short} object that
 308      * represents the {@code short} value indicated by the
 309      * {@code String} parameter. The string is converted to a
 310      * {@code short} value in exactly the manner used by the
 311      * {@code parseShort} method for radix 10.
 312      *
 313      * @param s the {@code String} to be converted to a
 314      *          {@code Short}
 315      * @throws  NumberFormatException If the {@code String}
 316      *          does not contain a parsable {@code short}.
 317      * @see     java.lang.Short#parseShort(java.lang.String, int)
 318      */
 319     public Short(String s) throws NumberFormatException {
 320         this.value = parseShort(s, 10);
 321     }
 322 
 323     /**
 324      * Returns the value of this {@code Short} as a
 325      * {@code byte}.

 326      */
 327     public byte byteValue() {
 328         return (byte)value;
 329     }
 330 
 331     /**
 332      * Returns the value of this {@code Short} as a
 333      * {@code short}.
 334      */
 335     public short shortValue() {
 336         return value;
 337     }
 338 
 339     /**
 340      * Returns the value of this {@code Short} as an
 341      * {@code int}.

 342      */
 343     public int intValue() {
 344         return (int)value;
 345     }
 346 
 347     /**
 348      * Returns the value of this {@code Short} as a
 349      * {@code long}.

 350      */
 351     public long longValue() {
 352         return (long)value;
 353     }
 354 
 355     /**
 356      * Returns the value of this {@code Short} as a
 357      * {@code float}.

 358      */
 359     public float floatValue() {
 360         return (float)value;
 361     }
 362 
 363     /**
 364      * Returns the value of this {@code Short} as a
 365      * {@code double}.

 366      */
 367     public double doubleValue() {
 368         return (double)value;
 369     }
 370 
 371     /**
 372      * Returns a {@code String} object representing this
 373      * {@code Short}'s value.  The value is converted to signed
 374      * decimal representation and returned as a string, exactly as if
 375      * the {@code short} value were given as an argument to the
 376      * {@link java.lang.Short#toString(short)} method.
 377      *
 378      * @return  a string representation of the value of this object in
 379      *          base 10.
 380      */
 381     public String toString() {
 382         return Integer.toString((int)value);
 383     }
 384 
 385     /**


   1 /*
   2  * Copyright (c) 1996, 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


 304     }
 305 
 306     /**
 307      * Constructs a newly allocated {@code Short} object that
 308      * represents the {@code short} value indicated by the
 309      * {@code String} parameter. The string is converted to a
 310      * {@code short} value in exactly the manner used by the
 311      * {@code parseShort} method for radix 10.
 312      *
 313      * @param s the {@code String} to be converted to a
 314      *          {@code Short}
 315      * @throws  NumberFormatException If the {@code String}
 316      *          does not contain a parsable {@code short}.
 317      * @see     java.lang.Short#parseShort(java.lang.String, int)
 318      */
 319     public Short(String s) throws NumberFormatException {
 320         this.value = parseShort(s, 10);
 321     }
 322 
 323     /**
 324      * Returns the value of this {@code Short} as a {@code byte} after
 325      * a narrowing primitive conversion.
 326      * @jls 5.1.3 Narrowing Primitive Conversions
 327      */
 328     public byte byteValue() {
 329         return (byte)value;
 330     }
 331 
 332     /**
 333      * Returns the value of this {@code Short} as a
 334      * {@code short}.
 335      */
 336     public short shortValue() {
 337         return value;
 338     }
 339 
 340     /**
 341      * Returns the value of this {@code Short} as an {@code int} after
 342      * a widening primitive conversion.
 343      * @jls 5.1.2 Widening Primitive Conversions
 344      */
 345     public int intValue() {
 346         return (int)value;
 347     }
 348 
 349     /**
 350      * Returns the value of this {@code Short} as a {@code long} after
 351      * a widening primitive conversion.
 352      * @jls 5.1.2 Widening Primitive Conversions
 353      */
 354     public long longValue() {
 355         return (long)value;
 356     }
 357 
 358     /**
 359      * Returns the value of this {@code Short} as a {@code float}
 360      * after a widening primitive conversion.
 361      * @jls 5.1.2 Widening Primitive Conversions
 362      */
 363     public float floatValue() {
 364         return (float)value;
 365     }
 366 
 367     /**
 368      * Returns the value of this {@code Short} as a {@code double}
 369      * after a widening primitive conversion.
 370      * @jls 5.1.2 Widening Primitive Conversions
 371      */
 372     public double doubleValue() {
 373         return (double)value;
 374     }
 375 
 376     /**
 377      * Returns a {@code String} object representing this
 378      * {@code Short}'s value.  The value is converted to signed
 379      * decimal representation and returned as a string, exactly as if
 380      * the {@code short} value were given as an argument to the
 381      * {@link java.lang.Short#toString(short)} method.
 382      *
 383      * @return  a string representation of the value of this object in
 384      *          base 10.
 385      */
 386     public String toString() {
 387         return Integer.toString((int)value);
 388     }
 389 
 390     /**