1
littleshy Mar 4, 2017
string 吧,不同类型以具体的为准。
|
2
ml3661190 Mar 4, 2017
输出 String 具体为什么我也不清楚,坐等大神解答
|
3
Kylinsun Mar 4, 2017 via Android
你传的是什么类型调用的就是什么样的方法。
|
4
chnyang Mar 4, 2017
输出的不应该是 String 么 ..
System.out.println("String"); |
5
ml3661190 Mar 4, 2017
不同类型以具体的为准。理解这句话应该就没问题了,我刚刚测试了一下
当传入的参数,未能有具体类型重载方法时,选择入参的的超类,也就是 Object 入参的方法 当有 Object , String , boolean 三个重载的方法时,传入 null 值,编译器则会报出一个 ambiguous 的编译异常 因为 String 跟 boolean 的方法都属于具体的类型,编译器无法判断选择那一个 大概就是这么个意思吧 |
7
yidinghe Mar 4, 2017 via Android
编译失败。
|
9
a1310747 OP @ml3661190 当有 Object , String , boolean 三个重载的方法时,传入 null 值,并不会报错 依然还是输出 String
|
10
Cloudee Mar 4, 2017 via iPhone
compile error
|
11
feiyuanqiu Mar 4, 2017
jls8 §15.12.2
--------------- There may be more than one such method, in which case the most specific one is chosen. The descriptor (signature plus return type) of the most specific method is the one used at run time to perform the method dispatch. https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.12.2 |
12
depress Mar 4, 2017
方法重载优先选子类
|
13
ovear Mar 4, 2017
优先匹配子类呀。。
|
14
feeeeeef Mar 4, 2017
编译不通过
|