【发布时间】:2017-01-13 18:26:40
【问题描述】:
考虑这段代码
class StockServer {
StockServer(String company, int Shares,double currentPrice, double cashOnHand) {}
double buy(int numberOfShares, double pricePerShare) {
System.out.println("buy(int,double)");
return 3.0;
}
float buy(long numberOfShares, double pricePerShare) {
System.out.println("buy(long,double)");
return 3.0f;
}
}
如果我执行这行代码,
StockServer a = new StockServer("",2,2.0,2);
byte b=5;
a.buy(b,2);
结果是:buy(int,double)
我想知道编译器如何决定执行哪个方法?
【问题讨论】:
-
也可以通过Relevant JLS Section
标签: java methods compiler-construction