Looks like 6 lines in both examples. And in calling code I also can't see any difference, since both support the same language constructs, including switch statements.
I see added potential with enums. It's the power of an object combined with the ease of an int. And you can't use a value like 481 where you expect only 0-1. The only "odd" value is null. In fact, I've written my own Enum class for projects in Java 1.4 that mimics enum in almost every thinkable way. The only thing I haven't been able to get to work is switch statements.
As for the Google Android link, that is for embedded systems where both available size and processor speed are a lot less than those of the usual machine used by users. So unless performance and size is really an issue, I'd go for enums every day of the week.
But then you still have to hard-code the ordinals as constants (public static final int), something I do not like. Ideally it would work exactly the same - the class fills in the name and ordinal for you. What if you want to add an enumerated value between two existing onces? With Java 1.5's enum, the ordinals will get shifted. That's something I'd like too.
In fact I have something like that but it has one flaw - it depends on Class.getDeclaredFields returning fields in the declared order. And that's an assumption that cannot be made. It works for now but it's not guaranteed to work.
Right, I've solved that problem for the greater part.
During object creating, I count the number of public static final fields of the same type that are not null. That's going to be the next ordinal. During the setting of the first object, it is created first. There are no non-null fields so the ordinal will be 0. It is then set, and the number of non-null fields will become one. And so on.
As for the name, in the name() method I loop through the fields again, and for all non-null fields without a name the name is set to be the same as the field's name. That should be called only during the first call to name() for all objects combined, unless of course it is called in a constructor.
This approach can still mix up the ordinal order but unfortunately that's something that can't be prevented. I think I'll give developers the chance to set them manually too.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com