Suppose I have an array of Object
s (specifically, an Object[]
) and an array of Constructor objects.
Can anybody refer me to some Java code that can look through the Constructor objects and choose the one is the most specific with respect to the actual types of the objects in my array. In other words, I'd like an implementation of the algorithm that javac
uses to choose among a set of overloaded methods.
You can look in a Java-based Java compiler (I hear OpenJDK has one).
I think you will find that name resolution is far trickier than you imagine, especially when you include generics and type erasure. I doubt you'll be able to "easily" lift this code out and use it on your own.
Most of the Java tools that do anything semantically deep use class files, where all that type erasure and resolution has happened, so they can avoid knowing how to do this. (The downside to only looking in class files is those tools can't modify source code at all).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With