简体   繁体   English

序列化字段类别

[英]Serialize Field Class

I need to pass java.lang.reflect.Field from one process to another using RMI, but Field does not implement Serializable interface. 我需要使用RMI将java.lang.reflect.Field从一个进程传递到另一个进程,但是Field没有实现Serializable接口。 how can I overcome this problem? 我该如何克服这个问题?

It doesn't make sense to pass a Field via RMI. 通过RMI传递字段没有任何意义。 A Field instance is really a dependent object of a java.lang.Class instance, and Class objects are not transmissible either. Field实例实际上是java.lang.Class实例的从属对象,并且Class对象也不可传输。 (And the reason that a Class is not transmissible is that it would present all sorts of nasty type checking problems ... considering that a Class instance actually denotes a reference type.) (而Class不可传递的原因是,它将出现各种讨厌的类型检查问题……考虑到Class实例实际上表示了引用类型。)

You will need to declare the relevant Field field as transient . 您将需要将相关的Field字段声明为transient If you want to transmit the Field information, you are probably going to need to pass it in the form of a field name / class name, and then reconstruct the Field at the other end in a custom readObject method. 如果要传输Field信息,则可能需要以字段名/类名的形式传递它,然后使用自定义readObject方法在另一端重建Field

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM