Enum as field/property not initialized with default value


I found a problem with how Enums are being handled when compiling to Java.

On C# (language level) Enums are value type. On Java, Enums are reference type, so they are nullable.

When declaring an object with an Enum field/property it will be initialized to the Enum with value 0 regardless if that value exists on the Enum or not. This is not happening on Java, so the value is left null which change the behavior of the code.



What do you think about this? Not a bug?

My concern is this is a language feature that is being translated for Enums that behave like BitMask, you convert them to int, so they get the default value Zero if not initialized. But this behavior is not carried over for regular Enums.


Sorry, missed the post. Enums should be value types everywhere, this is a bug.

Thanks, logged as bugs://84211

Can you give an example? We support two kinds of enums in cooper (Java backend),

java enums (which descend from java.lang.Enum) and C# style enums. You can force it to be a c# style enum if you do:

  enum Test: int { a, b, c} 

Or assign numeric values to any of the items.

I do think it’s worth discussing if we should change the default to not be a Java enum for C#. My only problem then is,how would we best express Java enums then in C# (in the cases you do need them).

Maybe enum Test: java.lang.Enum { a, b, c} for a Java enum, everything else is a value type? (same for Oxygene & co)?

bugs://84211 got closed with status fixed.

1 Like

bugs://84211 got reopened.

bugs://84211 got closed with status fixed.