Alex Rivera | Logout

Java Serializing Methods

Asked 2011-02-07T08:18:17.490
21

It is possible to serialize a method? Because when I look at the documentation the Method class does not implements Serializable. So are there any alternatives?

Edit
Report

2 Answers

11

Since Method does not implement Serializable, it cannot be serialized using the standard Java Serialization API.

A workaround would be to manually serialize just the name of the class and method and its parameter types. You can then recreate the Method instance during deserialization.

answered 2011-02-07T08:22:51.843
1

If you just wonder, is it possible, than no: it doesn't implement Serializable. Also, Method is a final class, so you can't subclass it in order to add some functionality.

answered 2011-02-07T08:23:37.480

Your Answer