< prev index next >

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

Print this page
rev 52786 : 8210031: implementation for JVM Constants API

@@ -23,10 +23,15 @@
  * questions.
  */
 
 package java.lang;
 
+import java.lang.invoke.MethodHandles;
+import java.lang.constant.Constable;
+import java.lang.constant.ConstantDesc;
+import java.util.Optional;
+
 import jdk.internal.math.FloatingDecimal;
 import jdk.internal.math.DoubleConsts;
 import jdk.internal.HotSpotIntrinsicCandidate;
 
 /**

@@ -44,11 +49,12 @@
  * @author  Lee Boynton
  * @author  Arthur van Hoff
  * @author  Joseph D. Darcy
  * @since 1.0
  */
-public final class Double extends Number implements Comparable<Double> {
+public final class Double extends Number
+        implements Comparable<Double>, ConstantDesc, Constable {
     /**
      * A constant holding the positive infinity of type
      * {@code double}. It is equal to the value returned by
      * {@code Double.longBitsToDouble(0x7ff0000000000000L)}.
      */

@@ -1068,8 +1074,33 @@
      */
     public static double min(double a, double b) {
         return Math.min(a, b);
     }
 
+    /**
+     * Returns a nominal descriptor for this instance, which is the instance
+     * itself.
+     *
+     * @return an {@link Optional} describing the {@linkplain Double} instance
+     * @since 12
+     */
+    @Override
+    public Optional<Double> describeConstable() {
+        return Optional.of(this);
+    }
+
+    /**
+     * Resolve this instance as a {@link ConstantDesc}, the result of which is
+     * the instance itself.
+     *
+     * @param lookup ignored
+     * @return the {@linkplain Double} instance
+     * @since 12
+     */
+    @Override
+    public Double resolveConstantDesc(MethodHandles.Lookup lookup) {
+        return this;
+    }
+
     /** use serialVersionUID from JDK 1.0.2 for interoperability */
     private static final long serialVersionUID = -9172774392245257468L;
 }
< prev index next >