Skip to content
This repository has been archived by the owner on Jun 21, 2022. It is now read-only.

RFC: Add DelegateFactory and DelegateInvocationHandler #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rschmitt
Copy link
Contributor

@rschmitt rschmitt commented Jun 1, 2015

At a minimum this needs to be gussied up with Javadoc, but I want to ensure that the feature is thought through conceptually.

@rschmitt
Copy link
Contributor Author

rschmitt commented Jun 4, 2015

Issues so far with this code:

  • Methods on java.lang.Object are indistinguishable from @Override methods on the proxy class itself
  • Default methods on a superinterface are also indistinguishable from @Override methods on the proxy class itself

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 superMethod and just delegate everything to the delegate unless an override can be found directly on the proxy class. However, I think what we actually want here is a more general interface. Instead of just passing in a MethodHandle superMethod, we want a tuple of (superMethod, source), where source can be an enum (OBJECT, DEFAULT, BASE_CLASS) or a Class or something.

@rschmitt
Copy link
Contributor Author

rschmitt commented Jun 4, 2015

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) { }

@bdonlan
Copy link
Owner

bdonlan commented Jun 12, 2015

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants