R
Rhino
I'm getting some odd problems in JDK 1.5.0_06 that involve enums. Can anyone
help me understand those problems better and suggest a solution?
I have recently discovered enums and I'm really glad I did; they provide a
much nicer way of handling some situations that have annoyed me for years.
Nevertheless, I don't pretend to fully understand all the ins and outs of
enums yet so maybe I have some conceptual gaps that are causing my current
problem(s) with enums.
Is there a problem with defining enums within interfaces and classes? Do
they need to be defined in their own separate source files, with one enum
per source file the way public classes are usually defined?
I was pretty sure that it was perfectly permissible to embed enum
definitions within both interfaces and classes but the problems I'm having
are making me wonder about that. I have an interface that contained an
imbedded enum and it was working fine when I tested my applet in the Eclipse
AppletViewer. When I tried the applet in IE6 though, the Sun Java console
apparently wasn't able to see the enum; I got a NoClassDefError for the
ResumeConstants$EmploymentHistoryConstants.class. EmploymentHistoryConstants
is my enum. For some reason, it seemed to expect a separate class file for
the enum. So, I moved it into a new Enum and deleted the enum from the
Interface, then regenerated my jar. That got me past that error.
However, it just got me to a different error, another NoClassDefError, this
time for StringUtils$WrappingCases.class. WrappingCases is an enum that was
embedded in my StringUtils class. The StringUtils class works fine in
Eclipse when accessed by a Java application and in my JApplet when I use the
AppletViewer. For some reason though, when I jar up the StringUtils class
and the rest of the pieces of the applet, Java seems to want the enum to be
in a separate file. As soon as I moved the WrappingCases enum to its own
separate file and jarred the pieces again, the applet worked fine.
What's going on here? Is this working the way it is supposed to or have I
got something messed up somewhere? Do I really need to put each enum in a
separate physical source file, the way I would a public class or an
interface? The examples in the articles about enums that I see in the Java
1.5 API don't seem to be doing that; they seem to embed the enums directly
within other classes.
help me understand those problems better and suggest a solution?
I have recently discovered enums and I'm really glad I did; they provide a
much nicer way of handling some situations that have annoyed me for years.
Nevertheless, I don't pretend to fully understand all the ins and outs of
enums yet so maybe I have some conceptual gaps that are causing my current
problem(s) with enums.
Is there a problem with defining enums within interfaces and classes? Do
they need to be defined in their own separate source files, with one enum
per source file the way public classes are usually defined?
I was pretty sure that it was perfectly permissible to embed enum
definitions within both interfaces and classes but the problems I'm having
are making me wonder about that. I have an interface that contained an
imbedded enum and it was working fine when I tested my applet in the Eclipse
AppletViewer. When I tried the applet in IE6 though, the Sun Java console
apparently wasn't able to see the enum; I got a NoClassDefError for the
ResumeConstants$EmploymentHistoryConstants.class. EmploymentHistoryConstants
is my enum. For some reason, it seemed to expect a separate class file for
the enum. So, I moved it into a new Enum and deleted the enum from the
Interface, then regenerated my jar. That got me past that error.
However, it just got me to a different error, another NoClassDefError, this
time for StringUtils$WrappingCases.class. WrappingCases is an enum that was
embedded in my StringUtils class. The StringUtils class works fine in
Eclipse when accessed by a Java application and in my JApplet when I use the
AppletViewer. For some reason though, when I jar up the StringUtils class
and the rest of the pieces of the applet, Java seems to want the enum to be
in a separate file. As soon as I moved the WrappingCases enum to its own
separate file and jarred the pieces again, the applet worked fine.
What's going on here? Is this working the way it is supposed to or have I
got something messed up somewhere? Do I really need to put each enum in a
separate physical source file, the way I would a public class or an
interface? The examples in the articles about enums that I see in the Java
1.5 API don't seem to be doing that; they seem to embed the enums directly
within other classes.