Skip to main content

enum type in Java Me

5 replies [Last post]
andyfei
Offline
Joined: 2007-11-30

New to Java Me: just found out that it seems I can't use "enum" type in ME. For new code I can get around that using constant integers. But I want to reuse some old Java code which uses enum without rewriting. Any way to make ME to accept enum type?

I am using EclipseME as IDE.

Thanks.

Andy

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
sfitzjava
Offline
Joined: 2003-06-15

This will only work if you are using a CDC implementation, and can get retroweaver to execute correctly in that environment. MIDP will not work as it does not support 1.4 JVM code. If retroweaver does not use any of the apis beyond 1.1.8jvm then you should be okay to recompile for a lower target level. But I think it has dependencies with jdk 1.4

Maybe the code can be ported!?

-Shawn

mflint
Offline
Joined: 2008-08-08

Looks like you're stuck, unless you replace the 1.5 enums with a type-safe enum pattern:

public final class AnEnum {
public static final AnEnum FIRST = new AnEnum("First");
public static final AnEnum SECOND = new AnEnum("Second");

private final String name;
private AnEnum(final String name)
{
this.name = name;
}
}

ullenboom
Offline
Joined: 2005-09-01

Yes. Use the http://retroweaver.sourceforge.net/. You compile with Java 5 language features and the Retroweaver modifies the byecode that it will run without problems on a 1.4 JM or on a mobile phone.

Bye,

Chris | http://www.tutego.com/

misha
Offline
Joined: 2003-06-11

Be aware that you will also need to add the retroweaver runtime to your application.
Misha
--

terrencebarr
Offline
Joined: 2004-03-04

Hi,

enum is a Java 1.5 language feature. Java ME is based on previous versions of Java so there is no language-level enum. If you have Java 1.5 code you want to run on Java ME you will need to modify it - this is also true for all other Java 1.5-specific language features. You'll find all problems by compiling your 1.5 code with the -version 1.4 compiler flag which forces the compiler to accept only 1.4 language features.

-- Terrence