Converting Java code to D

Mike James via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Apr 20 10:48:31 PDT 2015


On Monday, 20 April 2015 at 17:28:27 UTC, John Colvin wrote:
> On Monday, 20 April 2015 at 17:24:30 UTC, bearophile wrote:
>> John Colvin:
>>
>>> struct LineStyle
>>> {
>>>   enum NONE = "None";
>>>   enum SOLID = "Solid";
>>>   enum DASH = "Dash";
>>>   enum DOT = "Dot";
>>>   enum DASHDOT = "Dash Dot";
>>>   enum DASHDOTDOT = "Dash Dot Dot";
>>>
>>>   string label;
>>>
>>>   private this(string label)
>>>   {
>>>       this.label = label;
>>>   }
>>> }
>>
>> The constructor doesn't look very useful.
>>
>> Perhaps a named enum is safer.
>>
>> Bye,
>> bearophile
>
> True, the constructor doesn't really add anything here.
>
> To be honest, the combination of enumeration and runtime 
> variables in the Java code seems like a rubbish design, but 
> perhaps there's a good reason for it that I'm not aware of.

Maybe they extended enum to get over the lack of structs.

Looking at the spec for java enums it appears that you can return
an enumeration or the associated string using the original code.

Regards, -=mike=-


More information about the Digitalmars-d-learn mailing list