RFC: Add DelegateFactory and DelegateInvocationHandler#7
RFC: Add DelegateFactory and DelegateInvocationHandler#7rschmitt wants to merge 1 commit intobdonlan:masterfrom
Conversation
|
Issues so far with this code:
In both of these cases, the workaround would be to define an explicit delegation method, which is the opposite of what we actually want. The other workaround would be to ignore the |
|
This appears to be working so far: if (superMethod != null)
try {
// Before binding to superMethod, we have to verify that we're not actually binding
// to a method supplied by java.lang.Object, or a default superinterface method.
delegateClass.getDeclaredMethod(methodName, methodType.dropParameterTypes(0, 1).parameterArray());
return new ConstantCallSite(superMethod.asType(methodType));
} catch (NoSuchMethodException ignore) { } |
|
Using that method to probe for supers does mean that this may have surprising behavior when you subclass these wrappers (which is, admittedly, somewhat silly). Maybe it'd be better to just check for methods that are implemented in Object (or an interface default) vs other classes in the super chain. I'd also prefer to have the delegate be provided by a getDelegate() or similar method; this allows for e.g. wrappers that check that a delegate hasn't been invalidated on every call. |
At a minimum this needs to be gussied up with Javadoc, but I want to ensure that the feature is thought through conceptually.