8265130: Make ConstantDesc class hierarchy sealed

Reviewed-by: mchung, jvernee, vromero
This commit is contained in:
Gavin Bierman 2021-06-02 00:49:49 +00:00 committed by Vicente Romero
parent 00c7aeee00
commit 379376f078
6 changed files with 25 additions and 38 deletions

View file

@ -68,15 +68,6 @@ import java.lang.invoke.VarHandle.VarHandleDesc;
* {@link Object#equals(Object)} method. There is no guarantee that any
* particular entity will always be represented by the same descriptor instance.
*
* @apiNote In the future, if the Java language permits, {@linkplain ConstantDesc}
* may become a {@code sealed} interface, which would prohibit subclassing except by
* explicitly permitted types. Clients can assume that the following
* set of subtypes is exhaustive: {@link String}, {@link Integer},
* {@link Long}, {@link Float}, {@link Double}, {@link ClassDesc},
* {@link MethodTypeDesc}, {@link MethodHandleDesc}, and
* {@link DynamicConstantDesc}; this list may be extended to reflect future
* changes to the constant pool format as defined in JVMS 4.4.
*
* @see Constable
* @see ConstantDescs
*
@ -84,7 +75,16 @@ import java.lang.invoke.VarHandle.VarHandleDesc;
*
* @since 12
*/
public interface ConstantDesc {
public sealed interface ConstantDesc
permits ClassDesc,
MethodHandleDesc,
MethodTypeDesc,
Double,
DynamicConstantDesc,
Float,
Integer,
Long,
String {
/**
* Resolves this descriptor reflectively, emulating the resolution behavior
* of JVMS 5.4.3 and the access control behavior of JVMS 5.4.4. The resolution