我正在编写我的第一个大型Scala程序。在Java等价,我有一个包含标签和工具提示我的UI控件枚举:在Scala中枚举多个构造函数参数
public enum ControlText {
CANCEL_BUTTON("Cancel", "Cancel the changes and dismiss the dialog"),
OK_BUTTON("OK", "Save the changes and dismiss the dialog"),
// ...
;
private final String controlText;
private final String toolTipText;
ControlText(String controlText, String toolTipText) {
this.controlText = controlText;
this.toolTipText = toolTipText;
}
public String getControlText() { return controlText; }
public String getToolTipText() { return toolTipText; }
}
没关系使用枚举该的智慧。还有其他地方,我想做类似的事情。
我该如何在Scala中使用scala.Enumeration来做到这一点? Enumeration.Value类只接受一个字符串作为参数。我需要继承吗?
谢谢。
我也使用这个习语所有枚举类型。 – paradigmatic 2009-12-02 16:01:43
比我的回答更好,k肯定是 – 2009-12-02 17:35:53
最好有一个“密封的抽象类”作为父类,然后是所需的类或对象,然后,如果你想要一个case类的特定实例,可以使用_normal_对象而不是案件对象。 – 2009-12-02 17:41:21