I just returned to developing MIDP after 4 years of .NET 2 and Java 5 and 6. During this time, I really enjoyed using enumerations.
Enum is a language function that allows the developer to trust more parts of his code, especially in order to avoid or detect errors earlier (at compile time). Some other benefits can be found here: http://java.sun.com/j2se/1.5.0/docs/guide/language/enums.html
It was strange to me that I could not find them in MIDP 2.0. I have an error message:
The "enum" type should not be used as an identifier, since it is reserved for a keyword from source level 1.5 "
I had some experience in Java 1.4 some time ago, but I didnβt remember that. Sure some features of the newer versions of your high-level languages ββthat you get for granted ...
In any case, here is a good recommendation on how to do without them (if you are developing MIDP or dealing with code prior to Java 5): http://www.javacamp.org/designPattern/enum. HTML
To summarize (more detailed information and a good explanation, follow the previous link. Many thanks to the original author):
//The typesafe enum pattern public class Suit { private final String name; public static final Suit CLUBS =new Suit("clubs"); public static final Suit DIAMONDS =new Suit("diamonds"); public static final Suit HEARTS =new Suit("hearts"); public static final Suit SPADES =new Suit("spades"); private Suit(String name){ this.name =name; } public String toString(){ return name; } }
Do you have any other approaches to this problem?
ptdev source share