< prev index next >

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

Print this page
rev 52981 : 8215300: additional changes to constants API


3528      * @return  a string of length {@code 1} or {@code 2} containing
3529      *          as its single character the argument {@code codePoint}.
3530      * @throws IllegalArgumentException if the specified
3531      *          {@code codePoint} is not a {@linkplain Character#isValidCodePoint
3532      *          valid Unicode code point}.
3533      */
3534     static String valueOfCodePoint(int codePoint) {
3535         if (COMPACT_STRINGS && StringLatin1.canEncode(codePoint)) {
3536             return new String(StringLatin1.toBytes((char)codePoint), LATIN1);
3537         } else if (Character.isBmpCodePoint(codePoint)) {
3538             return new String(StringUTF16.toBytes((char)codePoint), UTF16);
3539         } else if (Character.isSupplementaryCodePoint(codePoint)) {
3540             return new String(StringUTF16.toBytesSupplementary(codePoint), UTF16);
3541         }
3542 
3543         throw new IllegalArgumentException(
3544             format("Not a valid Unicode code point: 0x%X", codePoint));
3545     }
3546 
3547     /**
3548      * Returns a nominal descriptor for this instance, which is the instance
3549      * itself.
3550      *
3551      * @return an {@link Optional} describing the {@linkplain String} instance
3552      * @since 12
3553      */
3554     @Override
3555     public Optional<String> describeConstable() {
3556         return Optional.of(this);
3557     }
3558 
3559     /**
3560      * Resolves this instance as a {@link ConstantDesc}, the result of which is
3561      * the instance itself.
3562      *
3563      * @param lookup ignored
3564      * @return the {@linkplain String} instance
3565      * @since 12
3566      */
3567     @Override
3568     public String resolveConstantDesc(MethodHandles.Lookup lookup) {
3569         return this;


3528      * @return  a string of length {@code 1} or {@code 2} containing
3529      *          as its single character the argument {@code codePoint}.
3530      * @throws IllegalArgumentException if the specified
3531      *          {@code codePoint} is not a {@linkplain Character#isValidCodePoint
3532      *          valid Unicode code point}.
3533      */
3534     static String valueOfCodePoint(int codePoint) {
3535         if (COMPACT_STRINGS && StringLatin1.canEncode(codePoint)) {
3536             return new String(StringLatin1.toBytes((char)codePoint), LATIN1);
3537         } else if (Character.isBmpCodePoint(codePoint)) {
3538             return new String(StringUTF16.toBytes((char)codePoint), UTF16);
3539         } else if (Character.isSupplementaryCodePoint(codePoint)) {
3540             return new String(StringUTF16.toBytesSupplementary(codePoint), UTF16);
3541         }
3542 
3543         throw new IllegalArgumentException(
3544             format("Not a valid Unicode code point: 0x%X", codePoint));
3545     }
3546 
3547     /**
3548      * Returns an {@link Optional} containing the nominal descriptor for this
3549      * instance, which is the instance itself.
3550      *
3551      * @return an {@link Optional} describing the {@linkplain String} instance
3552      * @since 12
3553      */
3554     @Override
3555     public Optional<String> describeConstable() {
3556         return Optional.of(this);
3557     }
3558 
3559     /**
3560      * Resolves this instance as a {@link ConstantDesc}, the result of which is
3561      * the instance itself.
3562      *
3563      * @param lookup ignored
3564      * @return the {@linkplain String} instance
3565      * @since 12
3566      */
3567     @Override
3568     public String resolveConstantDesc(MethodHandles.Lookup lookup) {
3569         return this;
< prev index next >