• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Licensed to the Apache Software Foundation (ASF) under one or more
3  *  contributor license agreements.  See the NOTICE file distributed with
4  *  this work for additional information regarding copyright ownership.
5  *  The ASF licenses this file to You under the Apache License, Version 2.0
6  *  (the "License"); you may not use this file except in compliance with
7  *  the License.  You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  */
17 
18 package java.lang;
19 
20 
21 /**
22  * The abstract superclass of the classes which represent numeric base types
23  * (that is {@link Byte}, {@link Short}, {@link Integer}, {@link Long},
24  * {@link Float}, and {@link Double}.
25  */
26 public abstract class Number implements java.io.Serializable {
27 
28     private static final long serialVersionUID = -8742448824652078965L;
29 
30     /**
31      * Empty default constructor.
32      */
Number()33     public Number() {
34     }
35 
36     /**
37      * Returns this object's value as a byte. Might involve rounding and/or
38      * truncating the value, so it fits into a byte.
39      *
40      * @return the primitive byte value of this object.
41      */
byteValue()42     public byte byteValue() {
43         return (byte) intValue();
44     }
45 
46     /**
47      * Returns this object's value as a double. Might involve rounding.
48      *
49      * @return the primitive double value of this object.
50      */
doubleValue()51     public abstract double doubleValue();
52 
53     /**
54      * Returns this object's value as a float. Might involve rounding.
55      *
56      * @return the primitive float value of this object.
57      */
floatValue()58     public abstract float floatValue();
59 
60     /**
61      * Returns this object's value as an int. Might involve rounding and/or
62      * truncating the value, so it fits into an int.
63      *
64      * @return the primitive int value of this object.
65      */
intValue()66     public abstract int intValue();
67 
68     /**
69      * Returns this object's value as a long. Might involve rounding and/or
70      * truncating the value, so it fits into a long.
71      *
72      * @return the primitive long value of this object.
73      */
longValue()74     public abstract long longValue();
75 
76     /**
77      * Returns this object's value as a short. Might involve rounding and/or
78      * truncating the value, so it fits into a short.
79      *
80      * @return the primitive short value of this object.
81      */
shortValue()82     public short shortValue() {
83         return (short) intValue();
84     }
85 }
86