nikgoodley-ibboost / funcito

Automatically exported from code.google.com/p/funcito
0 stars 0 forks source link

With final classes, check for non-final interfaces or base classes to proxy instead of always failing #52

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Since none of the proxying frameworks (Javassist, CGLIB, or Java Dynamic 
Proxies) can proxy a final class, Funcito currently fails to be able to wrap 
methods on those classes.  However, sometimes the method you want to wrap may 
actually exist on a interface or parent class (non-final) of the final class.

Funcito should be able to create the proxy for those interfaces or base classes 
instead, and then the method-wrapping would be successful.

For more informative error reporting, we would probably want to retain the 
identity of the original final class when proxying interfaces or parent 
classes, so in case the method-wrapping still fails there will be more 
information as to what happened.

Original issue reported on code.google.com by kandpwel...@gmail.com on 21 May 2012 at 3:36

GoogleCodeExporter commented 9 years ago

Original comment by kandpwel...@gmail.com on 21 May 2012 at 5:12

GoogleCodeExporter commented 9 years ago
When I examined the possibility closer, I realized that it would not be 
possible to implement this without abandoning type-safety, and hence forcing 
the user to cast everything.  So it would be simpler for the user to continue 
to just declare the function-objects to have a source type of the non-final 
base class or implemented interface of interest (i.e., the type that does 
declare the non-final method(s) to be wrapped).  In other words, while the goal 
was to be able to do:
   Function<String,Integer> f = functionFor(callsTo(String.class).length());
... they will instead have to continue to use:
   Function<CharSequence,Integer> f = functionFor(callsTo(CharSequence.class).length());

Original comment by kandpwel...@gmail.com on 27 May 2012 at 3:59