jdk/src/java.base/share/classes/java/lang/Number.java
changeset 28748 af951d0d2607
parent 25859 3317bb8137f4
equal deleted inserted replaced
28710:5b8db585a33c 28748:af951d0d2607
     1 /*
     1 /*
     2  * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1994, 2015, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    35  * a particular {@code Number} implementation to a given primitive
    35  * a particular {@code Number} implementation to a given primitive
    36  * type is defined by the {@code Number} implementation in question.
    36  * type is defined by the {@code Number} implementation in question.
    37  *
    37  *
    38  * For platform classes, the conversion is often analogous to a
    38  * For platform classes, the conversion is often analogous to a
    39  * narrowing primitive conversion or a widening primitive conversion
    39  * narrowing primitive conversion or a widening primitive conversion
    40  * as defining in <cite>The Java&trade; Language Specification</cite>
    40  * as defined in <cite>The Java&trade; Language Specification</cite>
    41  * for converting between primitive types.  Therefore, conversions may
    41  * for converting between primitive types.  Therefore, conversions may
    42  * lose information about the overall magnitude of a numeric value, may
    42  * lose information about the overall magnitude of a numeric value, may
    43  * lose precision, and may even return a result of a different sign
    43  * lose precision, and may even return a result of a different sign
    44  * than the input.
    44  * than the input.
    45  *
    45  *
    52  * @jls 5.1.3 Narrowing Primitive Conversions
    52  * @jls 5.1.3 Narrowing Primitive Conversions
    53  * @since   1.0
    53  * @since   1.0
    54  */
    54  */
    55 public abstract class Number implements java.io.Serializable {
    55 public abstract class Number implements java.io.Serializable {
    56     /**
    56     /**
    57      * Returns the value of the specified number as an {@code int},
    57      * Returns the value of the specified number as an {@code int}.
    58      * which may involve rounding or truncation.
       
    59      *
    58      *
    60      * @return  the numeric value represented by this object after conversion
    59      * @return  the numeric value represented by this object after conversion
    61      *          to type {@code int}.
    60      *          to type {@code int}.
    62      */
    61      */
    63     public abstract int intValue();
    62     public abstract int intValue();
    64 
    63 
    65     /**
    64     /**
    66      * Returns the value of the specified number as a {@code long},
    65      * Returns the value of the specified number as a {@code long}.
    67      * which may involve rounding or truncation.
       
    68      *
    66      *
    69      * @return  the numeric value represented by this object after conversion
    67      * @return  the numeric value represented by this object after conversion
    70      *          to type {@code long}.
    68      *          to type {@code long}.
    71      */
    69      */
    72     public abstract long longValue();
    70     public abstract long longValue();
    73 
    71 
    74     /**
    72     /**
    75      * Returns the value of the specified number as a {@code float},
    73      * Returns the value of the specified number as a {@code float}.
    76      * which may involve rounding.
       
    77      *
    74      *
    78      * @return  the numeric value represented by this object after conversion
    75      * @return  the numeric value represented by this object after conversion
    79      *          to type {@code float}.
    76      *          to type {@code float}.
    80      */
    77      */
    81     public abstract float floatValue();
    78     public abstract float floatValue();
    82 
    79 
    83     /**
    80     /**
    84      * Returns the value of the specified number as a {@code double},
    81      * Returns the value of the specified number as a {@code double}.
    85      * which may involve rounding.
       
    86      *
    82      *
    87      * @return  the numeric value represented by this object after conversion
    83      * @return  the numeric value represented by this object after conversion
    88      *          to type {@code double}.
    84      *          to type {@code double}.
    89      */
    85      */
    90     public abstract double doubleValue();
    86     public abstract double doubleValue();
    91 
    87 
    92     /**
    88     /**
    93      * Returns the value of the specified number as a {@code byte},
    89      * Returns the value of the specified number as a {@code byte}.
    94      * which may involve rounding or truncation.
       
    95      *
    90      *
    96      * <p>This implementation returns the result of {@link #intValue} cast
    91      * <p>This implementation returns the result of {@link #intValue} cast
    97      * to a {@code byte}.
    92      * to a {@code byte}.
    98      *
    93      *
    99      * @return  the numeric value represented by this object after conversion
    94      * @return  the numeric value represented by this object after conversion
   103     public byte byteValue() {
    98     public byte byteValue() {
   104         return (byte)intValue();
    99         return (byte)intValue();
   105     }
   100     }
   106 
   101 
   107     /**
   102     /**
   108      * Returns the value of the specified number as a {@code short},
   103      * Returns the value of the specified number as a {@code short}.
   109      * which may involve rounding or truncation.
       
   110      *
   104      *
   111      * <p>This implementation returns the result of {@link #intValue} cast
   105      * <p>This implementation returns the result of {@link #intValue} cast
   112      * to a {@code short}.
   106      * to a {@code short}.
   113      *
   107      *
   114      * @return  the numeric value represented by this object after conversion
   108      * @return  the numeric value represented by this object after conversion