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

前端 未结 5 1111
被撕碎了的回忆
被撕碎了的回忆 2020-11-28 15:48
package org.study.algos;
public class Study {

    public static void main(String[] args) {
       A a = new A();
       a.m1(null);
    }
 }
 class A {
    public v         


        
5条回答
  •  孤城傲影
    2020-11-28 16:25

    A String is an Object, an Object is not a String, thus the first overload is more specific than the second. See JLS 15.12.2, as Syntactic mentioned.

提交回复
热议问题