Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
请告诉我如何区分对象和 ObjectInputStream。比如它是 String 、 Image 还是等...?
您必须知道会发生什么并进行投射。您也可以使用 instanceof 进行检查,或者做一些更复杂的事情,例如在您执行的地图中注册处理程序
map.get(object.getClass()).handle(object);
但最重要的是,您必须知道可以编写正确处理代码的对象。