Hi, I have a question that for example I have a GameStartegy class that has 53 fields and the type of all is one interface for example Strategy and one of these fields are Date and the will be initialized when we create an object,how can i create a Serializable object ?? should I serialize all fields like Date? thanks
+1
A:
As long as the class implements the Serializable
interface, it is serializable.
Here's an introduction to serialization in java:
http://www.javacoffeebreak.com/articles/serialization/index.html
Cuga
2010-01-21 20:31:54
A:
First you need to implement serializable interface which is mark up interface once you class implements that interface then you can have Serilizable objects...
giri
2010-01-21 20:34:24
A:
Okay, java.util.Date is Serializable, so that shouldn't be a problem.
If you have member fields that you don't need to save, you can make them transient Transient members don't get serialized. So you can have class like this
class A implements Serializable{
int a;
transient NonSerialzableObject n;
}
That should work.
You can also create custom serialization functions by implementing the following functions:
private void writeObject(java.io.ObjectOutputStream out) throws IOException
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException;
Chad Okere
2010-01-21 20:36:47