How could interface injection implement a Meta Object Protocol?
There is a great project initialized by Attila Szegedi of the JVM-languages community to create a common meta object protocol (MOP) for all languages on the JVM. With interface injection this would be a simple task.
- Let all objects in your language (that supports the MOP) implement the (probably not injectable) interface
java.dyn.SupportsMetaObjectProtocol. An interface with only one method:
java.dyn.MetaObjectProtocol getMetaObjectProtocol();This would return the implementation of the
java.dyn.MetaObjectProtocolinterface for your particular language.
java.dyn.MetaObjectProtocolcontains methods for getting method handles for each dynamic language construct that the community have agreed to be a good common construct, such as getters and setters for subscript operations. These method handles would come from the actual implementation of them for your particular language, and would therefore benefit from every imaginable optimization you have cooked up for your language.
- When the main interface of my language is being injected into a class from your language it finds that your class implements
java.dyn.SupportsMetaObjectProtocoland uses that to get the method handles for all dynamic language constructs supported by my language, rebinding them them to the method names used in my language.
And as simple as that interface injection has been used to implement a common ground for all languages on the Java platform with absolutely no overhead.
I'm not saying that this is the way to implement a meta object protocol for the Java platform, I am just suggesting one way to do it, someone a lot smarter than me might come up with a much better implementation.
To sum things up: I can't wait until the JVM supports interface injection.