tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nikola Milutinovic <>
Subject [Slightly OT] JDK 1.5 + enum + serialization
Date Fri, 15 Jul 2005 20:10:56 GMT
Hi all.

I have a question, which is slightly off topic, but can crop up in TC.

SHORT VERSION: can a Java 1.5 enum be serilaized?


I have been working on project that uses it's own RPC via and I have run into a wall trying to send 
an enum via comm channel. I always get "InstantiationError". When I gave 
it a thought, it became clear that *that* operation is not possible.

Why? Well, enums look like classes, in that they can have methods, 
constructors and attributes. One major difference, though, is that 
constructor is NOT public and you cannot instantiate an object of type 
"enum". And, just to be absolutely clear, you shouldn't be able to do 
that with enums - they are not classes. Enums are like collections of 
named constants.

So, my question is basically, can enum be serialized via Java Serialization?

What does it have to do with TC? :-)

Well, TC uses serialization for session objects, when it shuts down, 
right? So, if you have objects that are enums or have enum attributes, 
what should you do? One solution, and that is the approach we're using, 
is to have an external representation of your enums, like int or String 
nad use that for serialization/deserialization.

Anyone has a better hint?


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message