I receive an object from the net through the the getInputStream() using ObjectInputStream
My question is: once it’s arrived from the net how can I distinguish it?Can i use instance of?
ObjectInputStream ois = new ObjectInputStream(socket.getInputStream();
Object obj = ois.readObject();
if(obj instanceof ObjectA)
...
else
...
First of all, it’s not the ObjectInputStream that will be tested to know the class of the object you received.
You should use :
Then you can you instanceof or you can use
o.getClass().getName(). Then you’ll know what type of object it is.