GithubHelp home page GithubHelp logo

Potentially replace argument List with Collection, Iterable, or Set: ByteBuddy#makeInterface, possibly other methods about byte-buddy HOT 7 CLOSED

raphw avatar raphw commented on July 19, 2024
Potentially replace argument List with Collection, Iterable, or Set: ByteBuddy#makeInterface, possibly other methods

from byte-buddy.

Comments (7)

raphw avatar raphw commented on July 19, 2024

This choice was made as the order in which the interfaces are declared is exposed via the reflection API. Because of this, it may affect code that uses reflection. Requiring lists should reflect this consequence.

Let me however think about it, I might adapt a different signature.

from byte-buddy.

rgoldberg avatar rgoldberg commented on July 19, 2024

If a List is passed as the argument to ByteBuddy#makeInterface(Collection), any iteration done inside the method will still be performed in the List order. So, since the method (and everything that it calls) only uses size() & iterator(), a (Collection) method will behave equivalently for a List argument as a (List) method.

The JavaDoc doesn't specify that the super interfaces will be declared in the order of their occurrence in the List, and it doesn't say how duplicates are handled (I would assume that an interface will be declared in the order of its first occurrence in the List). The same would hold true if you change the signature to (Collection c), and just specify that an interface will be declared in the order of it first occurrence in c.iterator(), which, for List, is obviously exactly the same as the order in the List itself.

If I, as the caller, don't care about the order of the interface declarations (or if I care about the order, but just want to specify it via some other Collection, like a SortedSet), why should makeInterface(...) care?

from byte-buddy.

raphw avatar raphw commented on July 19, 2024

I have adopted your suggestion with some additional validation of the input which was meaningful for lists that can (illegally) contain duplicates even though it would not be allowed. I adapted this throughout all of Byte Buddy's API where it appeared meaningful, i.e. where the order of arguments does not always have a meaning. I will soon push an updated version. Thanks for your input.

from byte-buddy.

rgoldberg avatar rgoldberg commented on July 19, 2024

Thanks for updating the API so quickly.

One additional makeInterface method might be useful.

Right now, you have:

makeInterface(Collection<? extends TypeDescription> typeDescriptions)

It would be simpler for a caller who just has Collection<Class<?>> to be able to call:

makeInterfaceFromClassCollection(Collection<Class<?>> classColl)

You can probably come up with a better name than makeInterfaceFromClassCollection; I just had to pic something that was different from makeInterface to avoid a duplicate method signature due to type erasure.

from byte-buddy.

raphw avatar raphw commented on July 19, 2024

You are right. Initially, I did not want to do it because I wanted to avoid polluting the API with additional method names. However, I will now add overloaded methods based on Iterable:

makeInterface(Iterable<? extends Class<?>> types)

from byte-buddy.

raphw avatar raphw commented on July 19, 2024

The changes are now in place.

from byte-buddy.

rgoldberg avatar rgoldberg commented on July 19, 2024

Thanks.

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.