Finding Java code that implements javac overload resolution algorithm

Suppose I have an array of Object (in particular, Object[] ) and an array of Constructor objects.

Can someone pass me some kind of Java code that can look through Constructor objects and select one of them, the most specific regarding the real types of objects in my array. In other words, I need an implementation of the algorithm that javac uses to select from a variety of overloaded methods.

+6
source share
1 answer

You can look in the Java Java compiler (I heard that OpenJDK has one).

I think you will find that name resolution is much more complicated than you imagine, especially when you turn on generics and erase styles. I doubt that you can "easily" remove this code and use it yourself.

Most Java tools that do something semantically deep use class files, where everything is erased and resolved by this type, so they may not know how to do it. (The disadvantage only for searching class files is that these tools cannot modify the source code at all).

+2
source

Source: https://habr.com/ru/post/903874/


All Articles