readobject method throws ClassNotFoundException

后端 未结 2 1304
谎友^
谎友^ 2020-11-30 12:57

I\'m trying to pick up Java and wanted to test around with Java\'s client/server to make the client send a simple object of a self defined class(Message) over to the server.

2条回答
  •  情歌与酒
    2020-11-30 13:34

    The reason is, that the readObject() in ObjectInputStream is practically implemented as:

     String s = readClassName();
     Class c = Class.forName(s); // Here your code breaks
     Object o = c.newInstance();
     ...populate o...
    

提交回复
热议问题