I am trying to use ObjectStreams to send and receive data through a socket connection. I would be using the RMI interface however android doesn't support it. Through my implementation I have multiple kinds of objects that I would like to read through the stream. For example if the client wanted to disconnect from a specified room they would send a Disconnect object through, if they wanted to chat someone they would send a chat object through ect.
I know that you have to type cast to use the object in java as so:
joinRoom = (Room) clientInput.readObject();
but if is there a way if i declare a generic object to tell what type it is and then determine how i will handle it?
maybe like this:
Object obj;
obj = (Object) clientInput.readObject();
and then use?
if(obj.getClass().equals(Room)){....}
if(obj.getClass().equals(Disconnect)){....}
thanks in advance.
instanceofexists, no need to do getClass().equals()