GithubHelp home page GithubHelp logo

Comments (7)

raphw avatar raphw commented on July 1, 2024

It is because Byte Buddy figured out that another method defined on the Object type is more suitable for binding. You can restrain this by defining:

MethodDelegation.to(new GeneralInterceptor(new ProxyedInterfaceDelegate(10L)))
                        .filter(not(isDeclaredBy(Object.class)))

to tell the method delegation not to consider the Object type's methods. However, this default behavior is a little bit unintuitive. I'll see if I find a more intuitive default for a future version without breaking the general idea of the MethodDelegation's binding algorithm.

from byte-buddy.

saden1 avatar saden1 commented on July 1, 2024

Awesome! I was thinking .method(isDeclaredBy(type)) would filter out object methods.

Thanks for the quick turnarounds and this fantastic library.

from byte-buddy.

raphw avatar raphw commented on July 1, 2024

For clarification: There are two filters involved:

  1. The filter for the methods of the dynamically generated type. Saying: When you define that you want to subclass(type), you are further saying you want to override methods that match isDeclaredBy(type) and let the others alone.
  2. The filter for the MethodDelegation where you are constraining to methods of your GeneralInterceptor that are not(isDeclaredBy(Object.class)), i.e. the intercept method.

In Byte Buddy 0.5, I added an additional AmbiguityResolver that automatically selects the method out of two that is declared by the most specific type which is a better default. This behavior bothered me before, I think this is a better approach for the future. Expect a release of this version sometime the year-shift.

PS: There is a bug fix release 0.4.1 available that allows you to use the InvocationHandlerAdapter if you want to. Its now also on Maven Central.

from byte-buddy.

saden1 avatar saden1 commented on July 1, 2024

Got it. I am already using the latest 0.4.1 release. Thank you so much.

from byte-buddy.

saden1 avatar saden1 commented on July 1, 2024

I just want to add that having to exclude Object class methods is quite problematic. It is preventing me from delegating calls to equals(...) method to an underlying implementation. Hopefully the new solution will allow me to delegate methods like equals.

from byte-buddy.

raphw avatar raphw commented on July 1, 2024

It does! It just prefers methods of a subtype without discarding them. You are also always free to configure your own AmbiguityResolver or to rearrange the existing ones. If you want to delegate to equals(Object), it however sounds like you might be able to use the more efficient Forwarding instrumentation which always delegates to a method with identical signature.

When filtering, you can always include the equals method by for example specifying not(isDeclaredBy(Object.class)).or(named("equals")).

from byte-buddy.

saden1 avatar saden1 commented on July 1, 2024

Excellent!

from byte-buddy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.