I’ve defined a IDL which I am compiling via IDLJ.exe. The IDL contains various different enum types. I notice that after code generation into .java source files the enum types are not actually enums but just regular classes with a set of final constants of the same type of the class.
I notice multiple different IDL code generators do this same thing including RTI’s rtiddsgen tool.
Is there any particular reason why code generators are not actually generating enums in Java using the java ‘enum’ keyword? Fields, constructors, and methods are supported inside enum types in java so I don’t think that would be a restriction.
Could it be class hierarchy restrictions? I know IDLJ generates classes that extend CORBA utilities, but RTI’s rtiddsgen doesn’t extend anything like that. Yet they both don’t use real enum types.
Advertisement
Answer
The code generation tools that you have mentioned are based on OMG’s IDL to Java Language Mapping specification. This spec mentions that “It is based upon versions of the Java JDK 1.1 and above” and therefore predates the use of native java enums.
OMG has a newer IDL4 to Java Language Mapping specification. In Table 7.1 Java Language Versions and Features it explicitly mentions the enumerations feature requiring java version J2SE 5.0. That spec is currently a beta release.