Search code examples
javaserializationrmi

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. how can I overcome this problem?


Solution

  • It doesn't make sense to pass a Field via RMI. A Field instance is really a dependent object of a java.lang.Class instance, and Class objects are not transmissible either. (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.)

    You will need to declare the relevant Field field as 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.