I have an application in which I need to se Dynamic, but I want strong typing. I want the compiler and the IDE to be able to check that I am using the right fields to access a given object, but I want that access mediated by a Dynamic (a proxy) object.
I have never liked the Java Proxy mechanism as I have to define things twice, and that is always a recipie for problems. Dynamic does away with the interface - which is good - but looses the strong typing - which is bad.
But it occurs to me that a typed Dynamic, i.e Dynamic[T], would allow for the best of both worlds. I get to intercept the field and method references, and the compiler can make sure I don’t ask for the wrong thing or assume it returns the wrong type.
Now changing Dynamic to add [T] would be difficult as it would not be backward compatible, but adding a new Dynamic (either TypedDynamic or maybe scala.typed.Dynamic) which did take a type would solve the problem.
The definition of TypedDynamic would be:-
trait TypedDynamic[T] extends T
and the compiler/IDE would then treat the object that extended TypedDynamic as though it were a T for all cases where a field or method reference was used but would use the Dynamic mechanism to deliver the field and method references to the code.