可以在Java中序列化Method对象吗? [英] Serialization of Method object in Java is possible?

查看:180
本文介绍了可以在Java中序列化Method对象吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试序列化一个Method对象时,我收到此错误。

I'm getting this error when I try to serialize a Method object.

java.io.NotSerializableException: java.lang.reflect.Method

任何想法?

推荐答案

无法以可移植的方式序列化方法对象,因为它不包含恢复它的所有必要信息(例如,字节码)。

There is no way to serialize a method object in a portable way since it doesn't contain all the necessary information to restore it (for example, the bytecode).

相反,您应该序列化类的名称,方法名称和参数类型。然后,您可以在反序列化期间重新创建方法实例。

Instead, you should serialize the name of the class, the method name and the parameter types. Then you can recreate the Method instance during deserialization.

这篇关于可以在Java中序列化Method对象吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆