There is a client-server that communicate with each other with silverized objects. The question arose how to determine which object came to the server in order to correctly recognize it?
A client who randomly sends 3 variants of an object
List <Integer> lInt = new ArrayList<>(); List <String> lStr= new ArrayList<>(); List <Object> lObj= new ArrayList<>(); ObjectOutputStream sOut = new ObjectOutputStream(socket.getOutputStream()); sOut.writeObject(lInt); sOut.writeObject(lStr); sOut.writeObject(lObj); The server that receives the object and deserializes it. But how can I understand what kind of object came in so that it can be projected then for example: lInt = (List "Integer") obj?
List <Integer> lInt = new ArrayList<>(); List <String> lStr= new ArrayList<>(); List <Object> lObj= new ArrayList<>(); ServerSocket serversocket = new ServerSocket(7800); Socket socket = serversocket.accept(); ObjectInputStream sIn = new ObjectInputStream(socket.getInputStream()); Object obj = null; while ((obj = sIn.readObject())!=null){ lInt = (List <Integer>)obj; ////ΠΡΠΈΠ±ΠΊΠ° Π΅ΡΠ»ΠΈ ΠΎΠ±ΡΠ΅ΠΊΡ Π½Π΅ List <Integer> }