Let's suppose you have an application where two J.V.M. cooperate across the wire (using some serialization).
Now consider things such as :
interface XY_R<X,Y,R> extends {X, Y => R} , Serializable {}
Some code using this (oos is an ObjectOutputStream and the code is in a static main) :
XY_R<Double,Double, Double> func = { Double x, Double y => x+y } ; oos.writeObject(func); Double db = new Double(3.14); XY_R<Double,Double, Double> func2 = { Double x, Double y => x+y*db } ; oos.writeObject(func2);
- Experiment with more complex closures (embarking instance data)
- Rewrite a command pattern with that (so one J.V.M can send a command to be executed by the other J.V.M) .
....
.....
Sad note: though this looks fun, deployment problems are tricky (unless you download dynamically the anonymous inner classes from the JVM which initiates ) ... so it's not such a good idea after all!
....
.....
Plus: since generics are a compile-time thing it does not make much sense here in a dynamic context so better stick to interface MyCommand extends {LocalContext => Result } , Serializable {}
.... I need vacations ....
No comments:
Post a Comment