Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Looking for Java code implementing javac's overload resolution algorithm

Suppose I have an array of Objects (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.

like image 678
Zack Avatar asked Dec 15 '11 21:12

Zack


1 Answers

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).

like image 138
Ira Baxter Avatar answered Oct 24 '22 22:10

Ira Baxter