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

Print this page

        

@@ -25,20 +25,21 @@
 
 package java.lang;
 
 import java.io.ObjectStreamField;
 import java.io.UnsupportedEncodingException;
+import java.lang.invoke.Constable;
+import java.lang.invoke.MethodHandles;
 import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Comparator;
 import java.util.Formatter;
 import java.util.Locale;
 import java.util.Objects;
 import java.util.Spliterator;
 import java.util.StringJoiner;
-import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.regex.PatternSyntaxException;
 import java.util.stream.IntStream;
 import java.util.stream.StreamSupport;
 import jdk.internal.HotSpotIntrinsicCandidate;

@@ -119,11 +120,11 @@
  * @since   1.0
  * @jls     15.18.1 String Concatenation Operator +
  */
 
 public final class String
-    implements java.io.Serializable, Comparable<String>, CharSequence {
+    implements java.io.Serializable, Comparable<String>, CharSequence, Constable<String> {
 
     /**
      * The value is used for character storage.
      *
      * @implNote This field is trusted by the VM, and is a subject to

@@ -2982,10 +2983,15 @@
      *          guaranteed to be from a pool of unique strings.
      * @jls 3.10.5 String Literals
      */
     public native String intern();
 
+    @Override
+    public String resolveConstant(MethodHandles.Lookup lookup) {
+        return this;
+    }
+
     ////////////////////////////////////////////////////////////////
 
     /**
      * Copy character bytes from this string into dst starting at dstBegin.
      * This method doesn't perform any range checking.