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™ 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
74 /**
75 * Returns the value of the specified number as a {@code float},
76 * which may involve rounding.
77 *
78 * @return the numeric value represented by this object after conversion
79 * to type {@code float}.
80 */
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},
|
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™ 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}. The
58 * particular semantics of the conversion operation from the specified
59 * number to an {@code int} are defined in subclasses. The operation may
60 * involve a narrowing conversion, rounding, or truncation.
61 *
62 * @return the numeric value represented by this object after conversion
63 * to type {@code int}.
64 *
65 * @jls 5.1.3 Narrowing Primitive Conversions
66 */
67 public abstract int intValue();
68
69 /**
70 * Returns the value of the specified number as a {@code long}. The
71 * particular semantics of the conversion operation from the specified
72 * number to a {@code long} are defined in subclasses. The operation may
73 * involve a narrowing conversion, rounding, or truncation.
74 *
75 * @return the numeric value represented by this object after conversion
76 * to type {@code long}.
77 *
78 * @jls 5.1.3 Narrowing Primitive Conversions
79 */
80 public abstract long longValue();
81
82 /**
83 * Returns the value of the specified number as a {@code float}. The
84 * particular semantics of the conversion operation from the specified
85 * number to a {@code float} are defined in subclasses. The operation may
86 * involve a narrowing conversion, rounding, or truncation.
87 *
88 * @return the numeric value represented by this object after conversion
89 * to type {@code float}.
90 *
91 * @jls 5.1.3 Narrowing Primitive Conversions
92 */
93 public abstract float floatValue();
94
95 /**
96 * Returns the value of the specified number as a {@code double}. The
97 * particular semantics of the conversion operation from the specified
98 * number to a {@code double} are defined in subclasses. The operation may
99 * involve a narrowing conversion, rounding, or truncation.
100 *
101 * @return the numeric value represented by this object after conversion
102 * to type {@code double}.
103 *
104 * @jls 5.1.3 Narrowing Primitive Conversions
105 */
106 public abstract double doubleValue();
107
108 /**
109 * Returns the value of the specified number as a {@code byte},
110 * which may involve rounding or truncation.
111 *
112 * <p>This implementation returns the result of {@link #intValue} cast
113 * to a {@code byte}.
114 *
115 * @return the numeric value represented by this object after conversion
116 * to type {@code byte}.
117 * @since 1.1
118 */
119 public byte byteValue() {
120 return (byte)intValue();
121 }
122
123 /**
124 * Returns the value of the specified number as a {@code short},
|