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

前端 未结 5 1115
被撕碎了的回忆
被撕碎了的回忆 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:18

    null value can be set to reference of any type. All overloaded methods you have are in one inheritance hierarchy Object <- String, the least general one is being choosen. But if you had two overloaded methods that are not in the same hierarchy, then you'd get compilation error about ambigous methods.

提交回复
热议问题