Note that there are some explanatory texts on larger screens.

plurals
  1. POJava enums in MIDP 2 mobile application
    text
    copied!<p>I've just got back to MIDP development after some 4 years of .NET 2 and Java 5 and 6. During that time I got to like using enums quite a lot.</p> <p>Enum is a language feature that allows a developer to have more confidence in some parts of his code, specially for being able to avoid or detect errors earlier (during compilation). Some other advantages can be found here: <strong>http:// java.sun.com/j2se/1.5.0/docs/guide/language/enums.html</strong></p> <p>I found it strange that I couldn't find them in MIDP 2.0. I've got this error message:</p> <blockquote> <p>"Type 'enum' should not be used as an identifier, since it is a reserved keyword from source level 1.5"</p> </blockquote> <p>I had some experience in Java 1.4 a while back, but I didn't remember this. There sure are some features of newer versions of your high-level languages that you get to take for granted...</p> <p>Anyway, here is a good recommendation for what to do without them (if you're developing MIDP or dealing with code prior to Java 5): <strong>http:// www.javacamp.org/designPattern/enum.html</strong></p> <p>Summing it up (for more details and a good explanation, follow the previous link. Many thanks to the original author):</p> <pre><code>//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; } } </code></pre> <p>Do you have any other different approaches to this issue?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload