【发布时间】:2020-01-14 17:59:03
【问题描述】:
我尝试了方法重载与自动装箱和加宽的不同组合。我被困在这里了。
public void bite(int a, byte b){
System.out.println("here in int-byte");
}
public void bite(byte a, int b){
System.out.println("here in byte-int");
}
主要:
byte a=9,b=8;
//int a=9,b=8;
bite(a, b);
这里出错
方法
bite(int, byte)对于类型Overloading是不明确的
当我反转方法定义发生时:
public void bite(byte a, int b){
System.out.println("here in byte-int");
}
public void bite(int a, byte b){
System.out.println("here in int-byte");
}
然后报错:
方法bite(byte, int)对于类型Overloading是不明确的
请解释这是怎么发生的。
【问题讨论】:
-
这能回答你的问题吗? overloading method priority in java
-
我已经经历了扩大的自动装箱概念,但我认为这里的问题有点不同,我问的是如何首先定义方法是报告错误。
标签: java methods overloading