Use of String.resolveConstantDesc in java 12

I was checking out all the new utility methods introduced in String class since java 8 and found this one method resolveConstantDesc which apparently takes a MethodHandles.Lookup as input.

However, the method simply ignores the input and returns the same instance.

/**
 * Resolves this instance as a {@link ConstantDesc}, the result of which is
 * the instance itself.
 *
 * @param lookup ignored
 * @return the {@linkplain String} instance
 * @since 12
 */
@Override
public String resolveConstantDesc(MethodHandles.Lookup lookup) {
    return this;
}

I don’t quite understand the use of this. Where will this be helpful? What are it’s use cases?

8

This method is required by the ConstantDesc interface that String implements.

ConstantDesc is part of the java.lang.constant package. The package description says

Classes and interfaces to represent nominal descriptors for run-time entities such as classes or method handles, and classfile entities such as constant pool entries or invokedynamic call sites. These classes are suitable for use in bytecode reading and writing APIs, invokedynamic bootstraps, bytecode intrinsic APIs, and compile-time or link-time program analysis tools.

So if you are not writing any of those things, you don’t need to worry about this method.

A ConstantDesc just represents an entry in the constant pool of a class file. String implements it because strings are one of the things that can go in the constant pool. Others include Integer, Double, ClassDesc, MethodTypeDesc etc. Integers, doubles, classes and methods are all things that can go in the constant pool. See also the Constant Pool section of the JVMS.

The point of resolveConstantDesc is that, given an entry in the constant pool (this), please turn it into an actual object at runtime. For String, this is trivially just the String itself. For ClassDesc, resolveConstantDesc returns a Class<?>, and for MethodTypeDesc it might return a MethodType. See an example of how this is implemented for a class here.

The point of the Lookup parameter is to enforce access control among other things. Again, for String, this is ignored because string constants are accessible from anywhere. For ClassDesc however, the class referenced by the constant pool entry might not be accessible from certain places. MethodHandles.Lookup can be used to enforce these things. Read its documentation if you are interested.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật