I noticed that the Proxy.newProxyInstance method takes an array of interfaces as the second argument. What confuses me is, I can't think of any case where we need to put multiple interfaces as the second argument since we have to cast the proxied object as one type (unless Java has the multitype casting I'm unaware of). Could anyone give me an example where we need to pass multiple interface into this method call?
There's an example on this page: http://www.javacodegeeks.com/2012/08/creating-java-dynamic-proxy.html. It doesn't use an explicit list, instead it uses a list returned by another method (Class.getInterfaces). The article doesn't go into detail about what happens if the class in question implements more than one interface, or for that matter if it doesn't implement any interfaces, but I speculate that particular code fragment might be why that method takes an array of interface classes rather than just an interface class.
posted 6 years ago
so, basically, only one interface will be relevant at a time right?
also, does anyone still using Java proxy instead of framework like CGLIB?
We're all out of roofs. But we still have tiny ads:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop