Saturday, 15 May 2010

Enums in Scala with multiple constructor parameters -


I am writing my first big scala program. In Java equivalents, I have a UI that stores labels and tooltips for my UI controls:

  Public NIL ControlText {CANCEL_BUTTON ("Cancel", "Cancel Change" and Dismiss the Dialog Do "), OK_BUTTON (" OK "," Save changes and dismiss dialog "), // ...; Private last string control text; Private end string tooltip text; ControlText (string control test, string tooltip text) {this.controlText = controlText; This.toolTipText = toolTipText; } Public string getControlText () {return controlText; } Public string getToolTipText () {Return Tool tip text; }}  

Never try to use enums for this, there are other places that I want to talk about.

How can I do this by using Scala? Calculation. Value class takes only one string as a parameter. Do I need this sub-class?

Thank you.

You can do what matches are used:

 < Code> Sealed Abstract Class ControlTextBase Case Class ControlText (controlText: String, toolTipText: String) Object Okbutan ControlText ("OK", "Save Changes and Dismiss") Object CancelButton Control Text ("Cancel", "Bull!") Increases  

No comments:

Post a Comment