New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enums #42
Enums #42
Conversation
Typing these from an offline airplane (never again, Gogo inflight!) so they are probably a bit different from the Classes and Lambdas proposals.
`enum value` `:` `name`*`[, value]`* | ||
|
||
The `enum value` command declares a value of an enum inside its declaration. | ||
If provided, the value must be an integer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why only integers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well I'll be darned, TS allows numbers in general. Makes sense.
This was a bit drafty :) I'll clean it up & do more syntax checking now. |
Ruby is killing me.
Unknown (0), | ||
Horizontal (1), | ||
Vertical (2) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, Java's a little more complicated. Enums can have constructors and take any number of values, but you have to implement the functionality yourself. An example:
enum Number {
One(1), Two(2), Three(3);
int numberValue;
Number(int v) {
numberValue = v;
}
int getValue() {
return numberValue;
}
}
// Then where you use it, you need to decide whether you want the enum type or the value, and can't convert implicitly.
int value = Number.One.getValue();
Number one = Number.One;
int valueFail = Number.One; // no good, need Number.One.getValue()
Typing these from an offline airplane (never again, Gogo inflight!) so they are probably a bit different from the Classes and Lambdas proposals.