I am looking for the correct signature of a method that accepts the func function and the arg argument, copies them over the network to the remote computer and returns the result. Currently, the signature looks like this:
def invokeRemote[A,B](address: String, func: A => B, arg: A): B
The problem is that the method throws a NotSerializable exception if the arguments are not Serializable or one of the primitive Java types.
I came up with the following solution to catch this error at compile time ...
type Func = (A => B) with Serializable def invokeRemote[A <: Serializable, B <: Serializable](address: String, func: Func, arg: A): B
... but now it is no longer possible to pass arguments like AnyVal , such as Int , Float or Double , which do not explicitly implement Serializable.
What should the method signature look like so that it accepts only Serializable objects or objects of type AnyVal as an argument?
source share