src/share/classes/java/lang/Number.java

Print this page
rev 10048 : 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
Reviewed-by:


  33  *
  34  * The specific semantics of the conversion from the numeric value of
  35  * a particular {@code Number} implementation to a given primitive
  36  * type is defined by the {@code Number} implementation in question.
  37  *
  38  * For platform classes, the conversion is often analogous to a
  39  * narrowing primitive conversion or a widening primitive conversion
  40  * as defining in <cite>The Java&trade; Language Specification</cite>
  41  * for converting between primitive types.  Therefore, conversions 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
  44  * than the input.
  45  *
  46  * See the documentation of a given {@code Number} implementation for
  47  * conversion details.
  48  *
  49  * @author      Lee Boynton
  50  * @author      Arthur van Hoff
  51  * @jls 5.1.2 Widening Primitive Conversions
  52  * @jls 5.1.3 Narrowing Primitive Conversions
  53  * @since   JDK1.0
  54  */
  55 public abstract class Number implements java.io.Serializable {
  56     /**
  57      * Returns the value of the specified number as an {@code int},
  58      * which may involve rounding or truncation.
  59      *
  60      * @return  the numeric value represented by this object after conversion
  61      *          to type {@code int}.
  62      */
  63     public abstract int intValue();
  64 
  65     /**
  66      * Returns the value of the specified number as a {@code long},
  67      * which may involve rounding or truncation.
  68      *
  69      * @return  the numeric value represented by this object after conversion
  70      *          to type {@code long}.
  71      */
  72     public abstract long longValue();
  73 


  81     public abstract float floatValue();
  82 
  83     /**
  84      * Returns the value of the specified number as a {@code double},
  85      * which may involve rounding.
  86      *
  87      * @return  the numeric value represented by this object after conversion
  88      *          to type {@code double}.
  89      */
  90     public abstract double doubleValue();
  91 
  92     /**
  93      * Returns the value of the specified number as a {@code byte},
  94      * which may involve rounding or truncation.
  95      *
  96      * <p>This implementation returns the result of {@link #intValue} cast
  97      * to a {@code byte}.
  98      *
  99      * @return  the numeric value represented by this object after conversion
 100      *          to type {@code byte}.
 101      * @since   JDK1.1
 102      */
 103     public byte byteValue() {
 104         return (byte)intValue();
 105     }
 106 
 107     /**
 108      * Returns the value of the specified number as a {@code short},
 109      * which may involve rounding or truncation.
 110      *
 111      * <p>This implementation returns the result of {@link #intValue} cast
 112      * to a {@code short}.
 113      *
 114      * @return  the numeric value represented by this object after conversion
 115      *          to type {@code short}.
 116      * @since   JDK1.1
 117      */
 118     public short shortValue() {
 119         return (short)intValue();
 120     }
 121 
 122     /** use serialVersionUID from JDK 1.0.2 for interoperability */
 123     private static final long serialVersionUID = -8742448824652078965L;
 124 }


  33  *
  34  * The specific semantics of the conversion from the numeric value of
  35  * a particular {@code Number} implementation to a given primitive
  36  * type is defined by the {@code Number} implementation in question.
  37  *
  38  * For platform classes, the conversion is often analogous to a
  39  * narrowing primitive conversion or a widening primitive conversion
  40  * as defining in <cite>The Java&trade; Language Specification</cite>
  41  * for converting between primitive types.  Therefore, conversions 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
  44  * than the input.
  45  *
  46  * See the documentation of a given {@code Number} implementation for
  47  * conversion details.
  48  *
  49  * @author      Lee Boynton
  50  * @author      Arthur van Hoff
  51  * @jls 5.1.2 Widening Primitive Conversions
  52  * @jls 5.1.3 Narrowing Primitive Conversions
  53  * @since   1.0
  54  */
  55 public abstract class Number implements java.io.Serializable {
  56     /**
  57      * Returns the value of the specified number as an {@code int},
  58      * which may involve rounding or truncation.
  59      *
  60      * @return  the numeric value represented by this object after conversion
  61      *          to type {@code int}.
  62      */
  63     public abstract int intValue();
  64 
  65     /**
  66      * Returns the value of the specified number as a {@code long},
  67      * which may involve rounding or truncation.
  68      *
  69      * @return  the numeric value represented by this object after conversion
  70      *          to type {@code long}.
  71      */
  72     public abstract long longValue();
  73 


  81     public abstract float floatValue();
  82 
  83     /**
  84      * Returns the value of the specified number as a {@code double},
  85      * which may involve rounding.
  86      *
  87      * @return  the numeric value represented by this object after conversion
  88      *          to type {@code double}.
  89      */
  90     public abstract double doubleValue();
  91 
  92     /**
  93      * Returns the value of the specified number as a {@code byte},
  94      * which may involve rounding or truncation.
  95      *
  96      * <p>This implementation returns the result of {@link #intValue} cast
  97      * to a {@code byte}.
  98      *
  99      * @return  the numeric value represented by this object after conversion
 100      *          to type {@code byte}.
 101      * @since   1.1
 102      */
 103     public byte byteValue() {
 104         return (byte)intValue();
 105     }
 106 
 107     /**
 108      * Returns the value of the specified number as a {@code short},
 109      * which may involve rounding or truncation.
 110      *
 111      * <p>This implementation returns the result of {@link #intValue} cast
 112      * to a {@code short}.
 113      *
 114      * @return  the numeric value represented by this object after conversion
 115      *          to type {@code short}.
 116      * @since   1.1
 117      */
 118     public short shortValue() {
 119         return (short)intValue();
 120     }
 121 
 122     /** use serialVersionUID from JDK 1.0.2 for interoperability */
 123     private static final long serialVersionUID = -8742448824652078965L;
 124 }