Dies ist eine alte Version des Dokuments!


Enumerations

Enumerations are supported. In an enum class two synthetic methods are created in the Bystecode.

  • values(): returns an array with all values, uses System.arraycopy
  • valueOf(String name): returns the value with the name name. This method calls valueOf of the class Enum. Though with a slightly different signature than what is present in our runtime library. That's why this case must be specially handled by the class file reader. Further, in the SSA a reference to the field ENUM$VALUES (which is synthetic as well) must be loaded. Finally, during code generation the address of this field has to be loaded and the reference to it must be fetched.


If enum values are used in a switch statement a special field $SWITCH_TABLE$CLASSNAME will be created in the class with the switch statement.
An excellent reference to the internals of enums can be found at http://www.straub.as/java/basic/enums.html.