In praise of Java 1.5 enums

T

Tim Tyler

Dale King said:
Tim Tyler wrote:

I hear you! I had the same reaction. I too thought that the reason that
they did generics the way they did was to have that backward
compatibility (Sun oddly calls this forward compatibility). I thought it
was going to be like the way nested classes were introduced. Nested
classes were introduced in 1.1, but the generated classes could run in
earlier VM's. But such was never their intention. But then why did we
end up with the lousy implementation of generics?

Maybe so that we could use third party tools to fix up the output from
the compiler, when the compiler is too stupid to do it itself - by the
look of it :-|
I have been told that there is an undocumented way to do it. You specify
jsr14 as the target.

-target jsr14 compiles the code. However it then fails in the same
way as compiling for Java 1.5 fails - when I try it here. I haven't
checked to see if the resulting bytecode is identical.
And if I don't mention it someone else will mention
retroweaver which is an open source tool to do it
(but which is not really a solution in my opinion).

Thanks for alerting us to the existence of
http://retroweaver.sourceforge.net/

However - even producing 1.4-compatible bytecode is not going to cope with
the VMs that check for major bytecode version number changes - and reject
code if it crosses a boundary. All the Netscape 4.xx JVMs did that,
for example. Nothing after Java 1.3.1 is likely to work for them.
 
R

Roedy Green

I have been told that there is an undocumented way to do it. You specify
jsr14 as the target. And if I don't mention it someone else will mention
retroweaver which is an open source tool to do it (but which is not
really a solution in my opinion).

I saw a sentence somewhere that hinted at the explanation. Generics
and emums are ok for JVM 1.4, but some other 1.5 features are not.
the Jet people mentioned that 1.5 has a ton of new native methods.

--
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
 
A

Adam P. Jenkins

Dale said:
I have been told that there is an undocumented way to do it. You specify
jsr14 as the target. And if I don't mention it someone else will mention
retroweaver which is an open source tool to do it (but which is not
really a solution in my opinion).

I'm not sure why you say that. Retroweaver solves the problem in
question for me; allows me to write code using 1.5 features, and emit
compiled code that runs under earlier JVMs. Of course it would be nicer
if Sun provided the option in their JDK, but adding a "retroweave" step
to your build really is equivalent to saying -source 1.5 -target 1.4,
except that you also need to distribute the retroweaver runtime jar with
your program. However I think the runtime jar would be unavoidable even
if Sun had a -target 1.4 option, because you have to provide some
equivalent of java.lang.Enum when running under older VMs.

Adam
 
D

Dale King

Adam said:
I'm not sure why you say that. Retroweaver solves the problem in
question for me; allows me to write code using 1.5 features, and emit
compiled code that runs under earlier JVMs. Of course it would be nicer
if Sun provided the option in their JDK, but adding a "retroweave" step
to your build really is equivalent to saying -source 1.5 -target 1.4,
except that you also need to distribute the retroweaver runtime jar with
your program. However I think the runtime jar would be unavoidable even
if Sun had a -target 1.4 option, because you have to provide some
equivalent of java.lang.Enum when running under older VMs.

The reason I say that and the reason that I think this is a big issues
is for those developers that develop libraries for use by others. Take
for example something like Jakarta Commons Collections. Let's say they
like generics and want to make their library support generics so that
those using 1.5 have generic versions of their classes. But they still
want to support users of 1.3 and 1.4.

Retroweaver is not really a solution because it would require users of
the library to also use the retroweaver library. That is too much of a
burden on users of the library.

They would basically be forced to maintain two different versions of the
source, one that is generic and one that is not. They would also have
two seperate library distributions leading to some confusion.

But why do we have to put up with this hassle? After all generics is a
compile time only thing.

Enums do not figure in because I am only talking about generics. What
they should have is something like -source 1.4-generics which would
imply -target 1.4. It would accept code with generics, but not Enums and
foreach which require runtime libary support (You could include static
import if you wanted). It would generate class files that would run and
could be used for compiling in a 1.4 system. The classes would also have
the attributes for accessing the generic features in a 1.5 compiler.

If this were the case then something like Jakarta Commons could be
generified without requiring maintaining two separate source and binary
distributions.

This is the model that was used long ago when inner classes were
introduced. Why not do the same thing for a major feature like generics.
Without it people like Jakarta Commons will delay moving to generics for
years slowing the overall adoption rate of generics. With it you would
see widespread adoption of generics since you don't lose that compatibility.
 
T

Tim Tyler

Adam P. Jenkins said:
Dale King wrote:

I'm not sure why you say that. Retroweaver solves the problem in
question for me; allows me to write code using 1.5 features, and emit
compiled code that runs under earlier JVMs. Of course it would be nicer
if Sun provided the option in their JDK, but adding a "retroweave" step
to your build really is equivalent to saying -source 1.5 -target 1.4,
except that you also need to distribute the retroweaver runtime jar with
your program. However I think the runtime jar would be unavoidable even
if Sun had a -target 1.4 option, because you have to provide some
equivalent of java.lang.Enum when running under older VMs.

The problem with Retroweaver from my point of view is the license.

The projects of mine which might be able to use retroweaver are
in the public domain - a nice and simple situation which most people
understand.

If they were deployed using retroweaver, I'd have to write something like:

``This project is in the public domain - apart from retroweaver -
which is copyrighted software, where the author retains ownership
and licenses the software to you under some legally-binding license
conditions, which you could get sued over if you violate the terms.
The license condtions can be found on:
http://retroweaver.sourceforge.net/overview.html
However, it wasn't clear to me if the runtime library shared these
conditions - and the source to those just says: "@author Toby Reyelts"
- and makes no mention of redistribution rights. I hope I have got
all this straight. Please don't worry about this too much:
while I've never met the author, I'm sure he values your well being
more than any money he could make out of suing you.''

:-(
 
T

Tim Tyler

Tim Tyler said:
The problem with Retroweaver from my point of view is the license.

....or rather license*s* - since there's also one that starts:

"Copyright (c) 2001 The Apache Software Foundation. All rights reserved."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,160
Latest member
CollinStri
Top