src/java.base/share/classes/java/lang/Long.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.math.*;
  30 import java.util.Objects;
  31 import jdk.internal.HotSpotIntrinsicCandidate;
  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 Long} class wraps a value of the primitive type {@code
  39  * long} in an object. An object of type {@code Long} contains a
  40  * single field whose type is {@code long}.
  41  *
  42  * <p> In addition, this class provides several methods for converting
  43  * a {@code long} to a {@code String} and a {@code String} to a {@code
  44  * long}, as well as other constants and methods useful when dealing
  45  * with a {@code long}.
  46  *
  47  * <p>Implementation note: The implementations of the "bit twiddling"
  48  * methods (such as {@link #highestOneBit(long) highestOneBit} and
  49  * {@link #numberOfTrailingZeros(long) 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 Long extends Number implements Comparable<Long> {
  60     /**
  61      * A constant holding the minimum value a {@code long} can
  62      * have, -2<sup>63</sup>.
  63      */
  64     @Native public static final long MIN_VALUE = 0x8000000000000000L;
  65 
  66     /**
  67      * A constant holding the maximum value a {@code long} can
  68      * have, 2<sup>63</sup>-1.
  69      */
  70     @Native public static final long MAX_VALUE = 0x7fffffffffffffffL;
  71 
  72     /**
  73      * The {@code Class} instance representing the primitive type
  74      * {@code long}.
  75      *
  76      * @since   1.1
  77      */
  78     @SuppressWarnings("unchecked")
  79     public static final Class<Long>     TYPE = (Class<Long>) Class.getPrimitiveClass("long");


2008      * @return the greater of {@code a} and {@code b}
2009      * @see java.util.function.BinaryOperator
2010      * @since 1.8
2011      */
2012     public static long max(long a, long b) {
2013         return Math.max(a, b);
2014     }
2015 
2016     /**
2017      * Returns the smaller of two {@code long} values
2018      * as if by calling {@link Math#min(long, long) Math.min}.
2019      *
2020      * @param a the first operand
2021      * @param b the second operand
2022      * @return the smaller of {@code a} and {@code b}
2023      * @see java.util.function.BinaryOperator
2024      * @since 1.8
2025      */
2026     public static long min(long a, long b) {
2027         return Math.min(a, b);





2028     }
2029 
2030     /** use serialVersionUID from JDK 1.0.2 for interoperability */
2031     @Native private static final long serialVersionUID = 4290774380558885855L;
2032 }


   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.math.*;
  32 import java.util.Objects;
  33 import jdk.internal.HotSpotIntrinsicCandidate;
  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 Long} class wraps a value of the primitive type {@code
  41  * long} in an object. An object of type {@code Long} contains a
  42  * single field whose type is {@code long}.
  43  *
  44  * <p> In addition, this class provides several methods for converting
  45  * a {@code long} to a {@code String} and a {@code String} to a {@code
  46  * long}, as well as other constants and methods useful when dealing
  47  * with a {@code long}.
  48  *
  49  * <p>Implementation note: The implementations of the "bit twiddling"
  50  * methods (such as {@link #highestOneBit(long) highestOneBit} and
  51  * {@link #numberOfTrailingZeros(long) 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 Long extends Number implements Comparable<Long>, Constable<Long> {
  62     /**
  63      * A constant holding the minimum value a {@code long} can
  64      * have, -2<sup>63</sup>.
  65      */
  66     @Native public static final long MIN_VALUE = 0x8000000000000000L;
  67 
  68     /**
  69      * A constant holding the maximum value a {@code long} can
  70      * have, 2<sup>63</sup>-1.
  71      */
  72     @Native public static final long MAX_VALUE = 0x7fffffffffffffffL;
  73 
  74     /**
  75      * The {@code Class} instance representing the primitive type
  76      * {@code long}.
  77      *
  78      * @since   1.1
  79      */
  80     @SuppressWarnings("unchecked")
  81     public static final Class<Long>     TYPE = (Class<Long>) Class.getPrimitiveClass("long");


2010      * @return the greater of {@code a} and {@code b}
2011      * @see java.util.function.BinaryOperator
2012      * @since 1.8
2013      */
2014     public static long max(long a, long b) {
2015         return Math.max(a, b);
2016     }
2017 
2018     /**
2019      * Returns the smaller of two {@code long} values
2020      * as if by calling {@link Math#min(long, long) Math.min}.
2021      *
2022      * @param a the first operand
2023      * @param b the second operand
2024      * @return the smaller of {@code a} and {@code b}
2025      * @see java.util.function.BinaryOperator
2026      * @since 1.8
2027      */
2028     public static long min(long a, long b) {
2029         return Math.min(a, b);
2030     }
2031 
2032     @Override
2033     public Long resolveConstant(MethodHandles.Lookup lookup) {
2034         return this;
2035     }
2036 
2037     /** use serialVersionUID from JDK 1.0.2 for interoperability */
2038     @Native private static final long serialVersionUID = 4290774380558885855L;
2039 }