Java中同一个套接字上的两个不同对象
发送者:
ObjectA A = new ObjectA();
ObjectB B = new ObjectB();
//Connection is created
socket.writeObject(B);
接收者:
//不知道如何找到我应该将对象类型转换到哪个对象:(
有没有办法在同一个对象流上发送两个不同的对象?
-Pk
Sender:
ObjectA A = new ObjectA();
ObjectB B = new ObjectB();
//Connection is created
socket.writeObject(B);
Receiver:
//don't know how to find to which object I should typecast the object to :(
Is there any way to send two different objects on the same Object stream?
-Pk
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
use
instanceof
两个对象相关吗?一个继承了另一个吗?如果是这样,您需要明确检查。
说A(父类)-> B
,因此
b instanceof B
和b instanceof A
将为 true。所以你需要小心。首先检查子类。use
instanceof
Are both the objects related? does one inherit the other? If so you'll need to check explicitly.
Say A (parent class) -> B
so
b instanceof B
andb instanceof A
will be true. So you need to be carefull. Check the child class first.