你的位置:首页 > 软件开发 > Java > TIJ英文原版书籍阅读之旅——Chapter Five:Initialization Cleanup

TIJ英文原版书籍阅读之旅——Chapter Five:Initialization Cleanup

发布时间:2015-06-11 00:00:21
Method overloading|_Distinguishing overloaded methodsIf the methods hava the same name, how can Java know which ...

Method overloading

|_Distinguishing overloaded methods

If the methods hava the same name, how can Java know which method you mean? There's a simple rule : Each overloaded method must take a unique list of argument types.

|_Overloading with primitives

We can know that the constant value 5 is treated as int, so if an overloaded method is available that takes as int, it is used. In all other cases, if you hava a data type that is smaller than the argument in the method, that data type is promoted. char produces a sightly different effect, since if it doesn't find an exact char match, it is promoted to int.

Suppose the methods take narrower primitive values. If your argument is wider, then you must perform a narrowing conversion with a cast. If you don't do this, the compiler will issue an error message.

|_Overloading on return values

void f() {}int f() {return 1;}

原标题:TIJ英文原版书籍阅读之旅——Chapter Five:Initialization Cleanup

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录