mercredi 13 septembre 2017

How to prepare an InvocationHandler for an interface not available at compiletime

Using reflection, it is possible to implement calls to methods of classes not available at compile time. This is an effective way to make it possible that framework code can work with different library-versions.

Now, say there is an interface

interface FutureIntf {
  method1(String s);
}

My code does not know this interface yet, but I would like to prepare an implementation for the time, this interface might be made available by the future library version, which needs to work with an implementation of this interface. I want to avoid javassist. I think there should be a way using java.lang.reflect.Proxy.newProxyInstance, could not figure out yet, how to do it effectively.





Aucun commentaire:

Enregistrer un commentaire