AbstractSlotsEnum

The AbstractSlotsEnum is an interface that helps ensure that object representations and access are consistent and correct. In particular, some operations in AvailObject (such as AvailObject.slot) are expected to operate on enumerations defined as inner classes within the Descriptor class for which the slot layout is specified.

There are two sub-interfaces, ObjectSlotsEnum and IntegerSlotsEnum. The representation access methods defined in AvailObjectRepresentation typically restrict the passed enumerations to be of the appropriate kind.

The Kotlin methods Enum.name and Enum.ordinal (and Java's corresponding but incompatible methods) are specified here, and in subclasses for Java compatibility, to ensure something that purports to be an Enum probably is so, and to make these methods available to it, even though neither Java nor Kotlin provides a mechanism to say an interface is only appropriate for subtypes of Enum – because it's a class.

Author

Mark van Gulik

Inheritors

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

In Java it was possible to define this interface in such a way that the name method was abstract and implemented by each specific Enum, but Kotlin breaks this mechanism. BUT – we're able to cast this to Enum to get to that field. I believe this code gets copied down into each specific Enum subclass, so the dynamic type check for the cast is trivially eliminated in each case. And worst case, Hotspot will be able to inline calls to this from sites that are known to be Enums.

Link copied to clipboard

In Java it was possible to define this interface in such a way that the ordinal() method was abstract and implemented by each specific Enum, but Kotlin breaks this mechanism. BUT – we're able to cast this to Enum to get to that field. I believe this code gets copied down into each specific Enum subclass, so the dynamic type check for the cast is trivially eliminated in each case. And worst case, Hotspot will be able to inline calls to this from sites that are known to be Enums.