Not at present. Serializing a function means storing its fields in the output stream of the object and deserializing it means reading the function object from the input stream of the object elsewhere. Deserialization assumes that the class of the object that is read from the input stream of the object is known by the JVM. Remember - functions are just objects behind the scene.
In this case, the server does not know the specific concrete class of the function object that you are serializing, it is possible that it implements the Function interface. To support this functionality, you need to find the class file of the corresponding function, send it to the server and upload it to the server using classloader . Then, if the object has any state, you can serialize the object on the client, send it over the network and deserialize it on the server. Only then can you use his methods. Assuming the objects in your function are stateless, which usually happens, you can skip the serialization / deserialization step.
EDIT:
Remember also that these functions may contain internal references to calling environments. This means that you can complete the serialization of the environment of the function object with it, which could potentially be your whole program.
source share