two questions on enums

Eric eric at makechip.com
Fri Apr 4 18:51:54 PDT 2014


By using the interface,
>> it also
>> forces the user to include all of the attributes of each pin 
>> such as
>> direction, max load, DC current, etc.  Since class type enums 
>> are references,
>> they are light, - and they should be immutable - so they are 
>> thread safe aslo.
>
> I'm not sure how you're using your enum. In Java, the only way 
> to perform a switch over an enum is if you know all the values 
> during compile time. Passing a type Enum into a function (i.e. 
> as opposed to "enum MyEnumType') requires using introspection 
> to pull the actual values out, and then a loop to scan through 
> them for your target value.
>
> But if you've programmed a switch for a known enum type, then 
> that means the enum has already been implemented and there is 
> no chance for more than one type to be passed in.
>
> So I'm confused.

I guess D does not see enums as enums, but rather as whatever
type the enum happens to implement. In java, all enums are
of enum type.  So it's probably me that's confused.

-Eric




More information about the Digitalmars-d-learn mailing list