How is ambiguity in selecting from overloaded methods resolved in Java?

It’s a fairly elaborate algorithm, detailed in JLS 15.12. But the part that is relevant here is 15.12.2, which says “the most specific one is chosen.” Both the Object and String overloads are “accessible and applicable” (the String is applicable because a null literal is a reference of all types), and the String is more specific.

EDIT: Corrected section, per Syntactic.

Leave a Comment