|
From: Colin S. <col...@ex...> - 2003-11-18 18:11:04
|
Chris Nokleberg wrote:
>Colin Sampaleanu wrote:
>
>
>>I think I may be missing something, but I think it's desireable to be
>>able to create in an easy fashion, 'closures' which encapsulate getting
>>a bean from a bean factory.
>>
>>Say you have an interface
>> interface MyInteface { ... whatever }
>>
>>and you have a factory Interface
>> interface MyInterfaceFactory {
>> MyInterface getInstance();
>> }
>>
>>
>
>You may want to look at:
>http://cglib.sourceforge.net/apidocs/net/sf/cglib/reflect/MethodDelegate.html
>
>It can create an object that implements an interface but delegates the
>implementation to a virtual or static method (with matching signature) of
>your choice. Essentially it is a implementation of C# delegates for Java.
>
>
Thanks Chris. I don't think though this provides any fundamental
advantage over just using AdvisedSupport in Spring as used by
ProxyFactoryBean. The fact that it only delegates to a method with a
matching signature is a problem too (unless I'm missing something). The
code would have to delegate to a method with an Object return value,
with the proxy doing something like a ClassCastException if the return
value (at runtime) didn't match.
|