Skip to content
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

Merged
merged 10 commits into from Apr 29, 2016
Merged

Enums #42

merged 10 commits into from Apr 29, 2016

Conversation

JoshuaKGoldberg
Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg commented Apr 25, 2016

Typing these from an offline airplane (never again, Gogo inflight!) so they are probably a bit different from the Classes and Lambdas proposals.

Typing these from an offline airplane (never again, Gogo inflight!) so
they are probably a bit different from the Classes and Lambdas
proposals.
@JoshuaKGoldberg JoshuaKGoldberg changed the title Added rough Enum design doc proposals Enums Apr 25, 2016
@JoshuaKGoldberg JoshuaKGoldberg added this to the Dogfood Ready milestone Apr 25, 2016
`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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why only integers?

Copy link
Member Author

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.

@JoshuaKGoldberg
Copy link
Member Author

This was a bit drafty :) I'll clean it up & do more syntax checking now.

Unknown (0),
Horizontal (1),
Vertical (2)
}
Copy link
Collaborator

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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants