On Monday, 20 April 2015 at 15:28:04 UTC, 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?

Regards,

-=mike=-

I'm not too hot at Java, but I'm pretty sure this gives you what you want. Perhaps "immutable" instead of "enum" would be closer to what Java does with enum members, but I don't know.

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;
    }
}

Reply via email to