The PermittedSubclasses attribute is a variable-length attribute in the attributes table of a ClassFile structure (§4.1). The PermittedSubclasses attribute records the classes and interfaces that are authorized to directly extend or implement the current class or interface (§5.3.5).
The Java programming language uses the modifier sealed to indicate a class or interface that limits its direct subclasses or direct subinterfaces. One might suppose that this modifier would correspond to an ACC_SEALED flag in a class file, since the related modifier final corresponds to the ACC_FINAL flag. In fact, a sealed class or interface is indicated in a class file by the presence of the PermittedSubclasses attribute.
There may be at most one PermittedSubclasses attribute in the attributes table of a ClassFile structure whose access_flags item does not have the ACC_FINAL flag set.
There must be no PermittedSubclasses attribute in the attributes table of a ClassFile structure whose access_flags item has the ACC_FINAL flag set.
sealed is distinct from final: a sealed class has a list of authorized subclasses, which a final class has no subclasses. Thus, a ClassFile structure may have a PermittedSubclasses attribute, or have its ACC_FINAL flag set, but not both.
The PermittedSubclasses attribute has the following format:
PermittedSubclasses_attribute {
u2 attribute_name_index;
u4 attribute_length;
u2 number_of_classes;
u2 classes[number_of_classes];
}
The items of the PermittedSubclasses_attribute structure are as follows:
-
attribute_name_index
The value of the
attribute_name_indexitem must be a valid index into theconstant_pooltable. Theconstant_poolentry at that index must be aCONSTANT_Utf8_infostructure (§4.4.7) representing the string "PermittedSubclasses". -
attribute_length
The value of the
attribute_lengthitem indicates the length of the attribute, excluding the initial six bytes. -
number_of_classes
The value of the
number_of_classesitem indicates the number of entries in theclassesarray. -
classes[]
Each value in the
classesarray must be a valid index into theconstant_pooltable. Theconstant_poolentry at that index must be aCONSTANT_Class_infostructure (§4.4.1) representing a class or interface which is authorized to directly extend or implement the current class or interface.The
classesarray is consulted when a class or interface is created that attempts to directly extend or implement the current class or interface (§5.3.5). Array items that represent classes or interfaces which do not attempt to directly extend or implement the current class or interface are ignored.