author | rriggs |
Sat, 01 Mar 2014 11:57:57 -0500 | |
changeset 23040 | 0cb50d5761df |
parent 10067 | 1263ecd22db6 |
child 24865 | 09b1d992ca72 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
10067
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
2 |
* Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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 |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.lang; |
|
27 |
||
28 |
/** |
|
10067
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
29 |
* The abstract class {@code Number} is the superclass of platform |
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
30 |
* classes representing numeric values that are convertible to the |
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
31 |
* primitive types {@code byte}, {@code double}, {@code float}, {@code |
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
32 |
* int}, {@code long}, and {@code short}. |
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
33 |
* |
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
34 |
* The specific semantics of the conversion from the numeric value of |
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
35 |
* a particular {@code Number} implementation to a given primitive |
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
36 |
* type is defined by the {@code Number} implementation in question. |
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
37 |
* |
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
38 |
* For platform classes, the conversion is often analogous to a |
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
39 |
* narrowing primitive conversion or a widening primitive conversion |
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
40 |
* as defining in <cite>The Java™ Language Specification</cite> |
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
41 |
* for converting between primitive types. Therefore, conversions may |
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
42 |
* lose information about the overall magnitude of a numeric value, may |
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
43 |
* lose precision, and may even return a result of a different sign |
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
44 |
* than the input. |
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
45 |
* |
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
46 |
* See the documentation of a given {@code Number} implementation for |
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
47 |
* conversion details. |
2 | 48 |
* |
49 |
* @author Lee Boynton |
|
50 |
* @author Arthur van Hoff |
|
10067
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
51 |
* @jls 5.1.2 Widening Primitive Conversions |
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
52 |
* @jls 5.1.3 Narrowing Primitive Conversions |
2 | 53 |
* @since JDK1.0 |
54 |
*/ |
|
55 |
public abstract class Number implements java.io.Serializable { |
|
56 |
/** |
|
10067
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
57 |
* Returns the value of the specified number as an {@code int}, |
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
58 |
* which may involve rounding or truncation. |
2 | 59 |
* |
60 |
* @return the numeric value represented by this object after conversion |
|
10067
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
61 |
* to type {@code int}. |
2 | 62 |
*/ |
63 |
public abstract int intValue(); |
|
64 |
||
65 |
/** |
|
10067
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
66 |
* Returns the value of the specified number as a {@code long}, |
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
67 |
* which may involve rounding or truncation. |
2 | 68 |
* |
69 |
* @return the numeric value represented by this object after conversion |
|
10067
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
70 |
* to type {@code long}. |
2 | 71 |
*/ |
72 |
public abstract long longValue(); |
|
73 |
||
74 |
/** |
|
10067
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
75 |
* Returns the value of the specified number as a {@code float}, |
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
76 |
* which may involve rounding. |
2 | 77 |
* |
78 |
* @return the numeric value represented by this object after conversion |
|
10067
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
79 |
* to type {@code float}. |
2 | 80 |
*/ |
81 |
public abstract float floatValue(); |
|
82 |
||
83 |
/** |
|
10067
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
84 |
* Returns the value of the specified number as a {@code double}, |
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
85 |
* which may involve rounding. |
2 | 86 |
* |
87 |
* @return the numeric value represented by this object after conversion |
|
10067
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
88 |
* to type {@code double}. |
2 | 89 |
*/ |
90 |
public abstract double doubleValue(); |
|
91 |
||
92 |
/** |
|
10067
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
93 |
* Returns the value of the specified number as a {@code byte}, |
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
94 |
* which may involve rounding or truncation. |
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
95 |
* |
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
96 |
* <p>This implementation returns the result of {@link #intValue} cast |
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
97 |
* to a {@code byte}. |
2 | 98 |
* |
99 |
* @return the numeric value represented by this object after conversion |
|
10067
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
100 |
* to type {@code byte}. |
2 | 101 |
* @since JDK1.1 |
102 |
*/ |
|
103 |
public byte byteValue() { |
|
104 |
return (byte)intValue(); |
|
105 |
} |
|
106 |
||
107 |
/** |
|
10067
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
108 |
* Returns the value of the specified number as a {@code short}, |
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
109 |
* which may involve rounding or truncation. |
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
110 |
* |
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
111 |
* <p>This implementation returns the result of {@link #intValue} cast |
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
112 |
* to a {@code short}. |
2 | 113 |
* |
114 |
* @return the numeric value represented by this object after conversion |
|
10067
1263ecd22db6
6253144: Long narrowing conversion should describe the algorithm used and implied "risks"
darcy
parents:
5506
diff
changeset
|
115 |
* to type {@code short}. |
2 | 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 |
} |