在Java中使用自动装箱和扩展来重载方法。
加宽是指将int等较小尺寸的数据类型传递给long等较大尺寸的数据类型。在这种情况下,方法可能会重载。
示例
public class Tester {
public static void main(String args[]) {
Tester tester = new Tester();
short c = 1, d = 2;
int e = 1, f = 2;
System.out.println(tester.add(c, d));
System.out.println(tester.add(e, f));
}
public int add(short a, short b) {
System.out.println("short");
return a + b;
}
public int add(int a, int b) {
System.out.println("int"); return a + b;
}
}输出结果
Short 3 Int 3
热门推荐
10 生日贺卡祝福语英文简短
11 简短的同事调离祝福语
12 朋友祝福语卡片简短大气
13 送病人简短的祝福语
14 兔年简短祝福语8字
15 学校校长新年祝福语简短
16 同事生日祝福语简短独特
17 生日祝福语简短霸气男
18 幽默祝福语押韵简短