src/java.base/share/classes/java/lang/Integer.java

Print this page




   9  * by Oracle in the LICENSE file that accompanied this code.
  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  *
  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.
  24  */
  25 
  26 package java.lang;
  27 
  28 import java.lang.annotation.Native;


  29 import java.util.Objects;
  30 import jdk.internal.HotSpotIntrinsicCandidate;
  31 import jdk.internal.misc.VM;
  32 
  33 import static java.lang.String.COMPACT_STRINGS;
  34 import static java.lang.String.LATIN1;
  35 import static java.lang.String.UTF16;
  36 
  37 /**
  38  * The {@code Integer} class wraps a value of the primitive type
  39  * {@code int} in an object. An object of type {@code Integer}
  40  * contains a single field whose type is {@code int}.
  41  *
  42  * <p>In addition, this class provides several methods for converting
  43  * an {@code int} to a {@code String} and a {@code String} to an
  44  * {@code int}, as well as other constants and methods useful when
  45  * dealing with an {@code int}.
  46  *
  47  * <p>Implementation note: The implementations of the "bit twiddling"
  48  * methods (such as {@link #highestOneBit(int) highestOneBit} and
  49  * {@link #numberOfTrailingZeros(int) numberOfTrailingZeros}) are
  50  * based on material from Henry S. Warren, Jr.'s <i>Hacker's
  51  * Delight</i>, (Addison Wesley, 2002).
  52  *
  53  * @author  Lee Boynton
  54  * @author  Arthur van Hoff
  55  * @author  Josh Bloch
  56  * @author  Joseph D. Darcy
  57  * @since 1.0
  58  */
  59 public final class Integer extends Number implements Comparable<Integer> {
  60     /**
  61      * A constant holding the minimum value an {@code int} can
  62      * have, -2<sup>31</sup>.
  63      */
  64     @Native public static final int   MIN_VALUE = 0x80000000;
  65 
  66     /**
  67      * A constant holding the maximum value an {@code int} can
  68      * have, 2<sup>31</sup>-1.
  69      */
  70     @Native public static final int   MAX_VALUE = 0x7fffffff;
  71 
  72     /**
  73      * The {@code Class} instance representing the primitive type
  74      * {@code int}.
  75      *
  76      * @since   1.1
  77      */
  78     @SuppressWarnings("unchecked")
  79     public static final Class<Integer>  TYPE = (Class<Integer>) Class.getPrimitiveClass("int");


1847      * @return the greater of {@code a} and {@code b}
1848      * @see java.util.function.BinaryOperator
1849      * @since 1.8
1850      */
1851     public static int max(int a, int b) {
1852         return Math.max(a, b);
1853     }
1854 
1855     /**
1856      * Returns the smaller of two {@code int} values
1857      * as if by calling {@link Math#min(int, int) Math.min}.
1858      *
1859      * @param a the first operand
1860      * @param b the second operand
1861      * @return the smaller of {@code a} and {@code b}
1862      * @see java.util.function.BinaryOperator
1863      * @since 1.8
1864      */
1865     public static int min(int a, int b) {
1866         return Math.min(a, b);





1867     }
1868 
1869     /** use serialVersionUID from JDK 1.0.2 for interoperability */
1870     @Native private static final long serialVersionUID = 1360826667806852920L;
1871 }


   9  * by Oracle in the LICENSE file that accompanied this code.
  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  *
  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.
  24  */
  25 
  26 package java.lang;
  27 
  28 import java.lang.annotation.Native;
  29 import java.lang.invoke.Constable;
  30 import java.lang.invoke.MethodHandles;
  31 import java.util.Objects;
  32 import jdk.internal.HotSpotIntrinsicCandidate;
  33 import jdk.internal.misc.VM;
  34 
  35 import static java.lang.String.COMPACT_STRINGS;
  36 import static java.lang.String.LATIN1;
  37 import static java.lang.String.UTF16;
  38 
  39 /**
  40  * The {@code Integer} class wraps a value of the primitive type
  41  * {@code int} in an object. An object of type {@code Integer}
  42  * contains a single field whose type is {@code int}.
  43  *
  44  * <p>In addition, this class provides several methods for converting
  45  * an {@code int} to a {@code String} and a {@code String} to an
  46  * {@code int}, as well as other constants and methods useful when
  47  * dealing with an {@code int}.
  48  *
  49  * <p>Implementation note: The implementations of the "bit twiddling"
  50  * methods (such as {@link #highestOneBit(int) highestOneBit} and
  51  * {@link #numberOfTrailingZeros(int) numberOfTrailingZeros}) are
  52  * based on material from Henry S. Warren, Jr.'s <i>Hacker's
  53  * Delight</i>, (Addison Wesley, 2002).
  54  *
  55  * @author  Lee Boynton
  56  * @author  Arthur van Hoff
  57  * @author  Josh Bloch
  58  * @author  Joseph D. Darcy
  59  * @since 1.0
  60  */
  61 public final class Integer extends Number implements Comparable<Integer>, Constable<Integer> {
  62     /**
  63      * A constant holding the minimum value an {@code int} can
  64      * have, -2<sup>31</sup>.
  65      */
  66     @Native public static final int   MIN_VALUE = 0x80000000;
  67 
  68     /**
  69      * A constant holding the maximum value an {@code int} can
  70      * have, 2<sup>31</sup>-1.
  71      */
  72     @Native public static final int   MAX_VALUE = 0x7fffffff;
  73 
  74     /**
  75      * The {@code Class} instance representing the primitive type
  76      * {@code int}.
  77      *
  78      * @since   1.1
  79      */
  80     @SuppressWarnings("unchecked")
  81     public static final Class<Integer>  TYPE = (Class<Integer>) Class.getPrimitiveClass("int");


1849      * @return the greater of {@code a} and {@code b}
1850      * @see java.util.function.BinaryOperator
1851      * @since 1.8
1852      */
1853     public static int max(int a, int b) {
1854         return Math.max(a, b);
1855     }
1856 
1857     /**
1858      * Returns the smaller of two {@code int} values
1859      * as if by calling {@link Math#min(int, int) Math.min}.
1860      *
1861      * @param a the first operand
1862      * @param b the second operand
1863      * @return the smaller of {@code a} and {@code b}
1864      * @see java.util.function.BinaryOperator
1865      * @since 1.8
1866      */
1867     public static int min(int a, int b) {
1868         return Math.min(a, b);
1869     }
1870 
1871     @Override
1872     public Integer resolveConstant(MethodHandles.Lookup lookup) {
1873         return this;
1874     }
1875 
1876     /** use serialVersionUID from JDK 1.0.2 for interoperability */
1877     @Native private static final long serialVersionUID = 1360826667806852920L;
1878 }