src/share/classes/java/lang/Byte.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


 307      *
 308      * @param s         the {@code String} to be converted to a
 309      *                  {@code Byte}
 310      * @throws           NumberFormatException If the {@code String}
 311      *                  does not contain a parsable {@code byte}.
 312      * @see        java.lang.Byte#parseByte(java.lang.String, int)
 313      */
 314     public Byte(String s) throws NumberFormatException {
 315         this.value = parseByte(s, 10);
 316     }
 317 
 318     /**
 319      * Returns the value of this {@code Byte} as a
 320      * {@code byte}.
 321      */
 322     public byte byteValue() {
 323         return value;
 324     }
 325 
 326     /**
 327      * Returns the value of this {@code Byte} as a
 328      * {@code short}.

 329      */
 330     public short shortValue() {
 331         return (short)value;
 332     }
 333 
 334     /**
 335      * Returns the value of this {@code Byte} as an
 336      * {@code int}.

 337      */
 338     public int intValue() {
 339         return (int)value;
 340     }
 341 
 342     /**
 343      * Returns the value of this {@code Byte} as a
 344      * {@code long}.

 345      */
 346     public long longValue() {
 347         return (long)value;
 348     }
 349 
 350     /**
 351      * Returns the value of this {@code Byte} as a
 352      * {@code float}.

 353      */
 354     public float floatValue() {
 355         return (float)value;
 356     }
 357 
 358     /**
 359      * Returns the value of this {@code Byte} as a
 360      * {@code double}.

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


   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


 307      *
 308      * @param s         the {@code String} to be converted to a
 309      *                  {@code Byte}
 310      * @throws           NumberFormatException If the {@code String}
 311      *                  does not contain a parsable {@code byte}.
 312      * @see        java.lang.Byte#parseByte(java.lang.String, int)
 313      */
 314     public Byte(String s) throws NumberFormatException {
 315         this.value = parseByte(s, 10);
 316     }
 317 
 318     /**
 319      * Returns the value of this {@code Byte} as a
 320      * {@code byte}.
 321      */
 322     public byte byteValue() {
 323         return value;
 324     }
 325 
 326     /**
 327      * Returns the value of this {@code Byte} as a {@code short} after
 328      * a widening primitive conversion.
 329      * @jls 5.1.2 Widening Primitive Conversions
 330      */
 331     public short shortValue() {
 332         return (short)value;
 333     }
 334 
 335     /**
 336      * Returns the value of this {@code Byte} as an {@code int} after
 337      * a widening primitive conversion.
 338      * @jls 5.1.2 Widening Primitive Conversions
 339      */
 340     public int intValue() {
 341         return (int)value;
 342     }
 343 
 344     /**
 345      * Returns the value of this {@code Byte} as a {@code long} after
 346      * a widening primitive conversion.
 347      * @jls 5.1.2 Widening Primitive Conversions
 348      */
 349     public long longValue() {
 350         return (long)value;
 351     }
 352 
 353     /**
 354      * Returns the value of this {@code Byte} as a {@code float} after
 355      * a widening primitive conversion.
 356      * @jls 5.1.2 Widening Primitive Conversions
 357      */
 358     public float floatValue() {
 359         return (float)value;
 360     }
 361 
 362     /**
 363      * Returns the value of this {@code Byte} as a {@code double}
 364      * after a widening primitive conversion.
 365      * @jls 5.1.2 Widening Primitive Conversions
 366      */
 367     public double doubleValue() {
 368         return (double)value;
 369     }
 370 
 371     /**
 372      * Returns a {@code String} object representing this
 373      * {@code Byte}'s value.  The value is converted to signed
 374      * decimal representation and returned as a string, exactly as if
 375      * the {@code byte} value were given as an argument to the
 376      * {@link java.lang.Byte#toString(byte)} 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     /**