On Thu, 27 Apr 2023 17:23:58 GMT, Mandy Chung <mch...@openjdk.org> wrote:
> 4. Return a string representation of internal name for a class or interface > and a descriptor string for a primitive type and array. The method could be > called `classDescString`. The caller can test if this `ClassDesc` is not a > primitive if it wants the string for a class or interface or an array. I think I will still resort to an `Optional`. Pros of Optional: 1. Clearly indicates to users that some ClassDesc cannot be converted to a CONSTANT_Class_info string, than failing at primitive classes at runtime (#12996) 2. Anticipates valhalla changes; if non-null types in Valhalla has descriptors but cannot be encoded in CONSTANT_Class_info, then users that check Optional will not break, as opposed to checking isPrimitive (similar story with `Lookup::hasPrivateAccess`) Cons of Optional: 1. Needs wrap and unwrap, not beautiful in code and has no pattern matching - The unwrap performance overhead will be gone in Valhalla with value classes So, I most likely will add `ClassDesc.ofClassDescString()` and `ClassDesc.classDescString()` returning `Optional<String>` to interact with `CONSTANT_Class_info`. With this new model, we will have: default ClassEntry classEntry(ClassDesc classDesc) { return classEntry(utf8Entry(classDesc.classDescString().orElseThrow(() -> new IllegalArgumentException(classDesc + " cannot be encoded as ClassEntry")))); } which will take care of non-primitive cases from valhalla. ------------- PR Comment: https://git.openjdk.org/jdk/pull/13598#issuecomment-1526093150