October 31st, 2012, 01:58 AM
ObjectOutputStream and new class()
OK . I need an answer to this so i'll do it short and sweet.
I'm using ObjectOutputStream to send objects from a server to my client.
I made my own class (lets say X) that implements Serializable to be sent by my OOS.
I have a timer that call a function that send this object 10 times;
Inside the function I do X.anInt++; to increment the public int value inside the object.
Just before sending I verify with a System.out.println(X.anInt) the value of this int which shows up to be correct
After sending the client receive it with the wrong int value which remains at the initial 0;
I noticed that the only way to get the right value on the client is to make a new X(); and assign to it the new good values every time before sending
I just don't get it ... WHY! I'm testing the variable value before sending and it is CORRECT .... why do I have to make a NEW... why is the object showing good values before beeing sent and wrong ones once received and cast to its right class...
I'm pretty sure that once I'll understand that i'll be a better person.
Thanks in advance
October 31st, 2012, 03:42 PM
Without some sort of SSCCE we'd just be taking a stab in the dark. Show some code.