Nice TWiki > Dev > NiceDiscussions? > EnumImplementation (r1.1) TWiki webs:
Dev | Doc | Main | TWiki | Sandbox
Dev . { Changes | Index | Search | Go }
Nice will get enums soon but first the exact implementation and syntax needs to be discussed.

A good starting point is the java 1.5 enum proposal: http://www.jcp.org/aboutJava/communityprocess/jsr/tiger/enum.html

An example of the java proposal:

public enum Coin {
  penny(1), nickel(5), dime(10), quarter(25);
 
  Coin(int value) { this.value = value; }

  private final int value;
  public int value() { return value; }
}
In Nice we could make the syntax simpler:
public enum Coin(int value) { penny(1), nickel(5),  dime(10),  quarter(25)}
And the compiler would generate in case of this example something like:
abstract class Coin implement Enum {
final Coin penny = new penny();
final Coin nickel = new penny();
final Coin dime = new penny();
final Coin quarter = new penny();
}
final class penny extends Coin{}
final class nickel extends Coin{}
final class dime extends Coin{}
final class quarter extends Coin{}

int value(Coin);
value(f@penny) = 1;
value(f@nickel) = 5;
value(f@dime) = 10;
value(f@quarter) = 25;

-- ArjanB - 30 Apr 2003

Topic EnumImplementation . { Edit | Attach | Ref-By | Printable | Diffs | r1.8 | > | r1.7 | > | r1.6 | More }
Revision r1.1 - 30 Apr 2003 - 09:28 GMT - ArjanB
Parents: NiceDiscussions?
Copyright © 1999-2003 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback.