samedi 23 avril 2016

Java: Is it possible to add a proxy to a live object instance during runtime?

I know Java supports proxies. I've been checking Javassist but not sure whether it can support the following trick:

public class Hello {

    public void hi() {
        System.out.println("hi");
    }
}

Hello hello = new Hello();

Hello proxyHello = createProxy(hello);
proxyHello.hi(); // method will be intercepted by a predefined proxy

Is it possible to do something like that?





Aucun commentaire:

Enregistrer un commentaire