• Post Reply Bookmark Topic Watch Topic
  • New Topic

java.io.Serializable Problem

 
ch praveen
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Friends,
Iam programming a muticlient, chatserver based on appletservlet communication. When I tried to pass Enumeration object to ObjectOutputStream's, writeObject(Object obj) method I got an exception at runtime (not at compile time) stating that Enumeration doen't implements Serializable interface. Then I created a class, SerializableWrapper that implements Serializable interface and wraps any Object. Eventhough I got the same exception, then I have implemented Hastable to make things better.
Now my question is, if we build a class that implements Serializable interface and wraps datatypes such as String and so on, it is working well with writeObject() method. Moreever if this class doesn't implement Serializable interface, an exception is thrown at compiletime itself but if same class wraps, Enumeration object, it is not working with writeObject() method and error is not thrown at compiletime.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I understand your problem - the compiler can't possibly figure out if all the objects that could be referred to in your class can be serialized. It can only be determined when you actually try to serialize based on the actual objects encountered.
Bill
 
Sajee Joseph
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thus for the above discussion is it correct to assume that
1. There is nothing that a Servlet constructor cant achieve that an init() can achieve ( init without the config object).
2. Thus usage of init() and constructor are 'either-or' situations.
Correct me if im wrong
Regards,
Sajee
 
Panagiotis Varlagas
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's the wrong thread Sajee
Originally posted by Sajee Joseph:
Thus for the above discussion is it correct to assume that
1. There is nothing that a Servlet constructor cant achieve that an init() can achieve ( init without the config object).
2. Thus usage of init() and constructor are 'either-or' situations.
Correct me if im wrong
Regards,
Sajee
 
Panagiotis Varlagas
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ch praveen,

You may want to check this out:
http://java.sun.com/docs/books/tutorial/essential/io/providing.html
Also (important point): When you want to serialize an object, since a object, in general, contains references (pointers) to other objects, you have to ensure that everything in the object graph is serializable
(or otherwise mark it as transient).
Hope this helps,
Panagiotis.
[ March 15, 2004: Message edited by: Panagiotis Varlagas ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!