Converting Java code to D
Steven Schveighoffer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Apr 20 11:05:25 PDT 2015
On 4/20/15 11:28 AM, Mike James wrote:
> Here is a fragment of Java code from an SWT program...
>
> public enum LineStyle {
> NONE("None"),
> SOLID("Solid"),
> DASH("Dash"),
> DOT("Dot"),
> DASHDOT("Dash Dot"),
> DASHDOTDOT("Dash Dot Dot");
>
> public final String label;
>
> private LineStyle(String label) {
> this.label = label;
> }
> }
>
> What would be the best ('canonical') way of translating it to D?
enum LineStyle : string {
NONE = "None",
SOLID = "Solid",
... // etc
}
Used like this:
funcThatTakesString(LineStyle.NONE);
LineStyle ls = LineStyle.SOLID;
funcThatTakesLineStyle(ls);
I'm not a Java programmer, and my time with Java was before enums. But
this is how I would do it.
-Steve
More information about the Digitalmars-d-learn
mailing list