高洛峰2017-04-18 10:50:49
It should be convenient to use. The parameters passed in the function are different but the function is the same. I think it's a habit and style. You don’t have to do this either
PHP中文网2017-04-18 10:50:49
In fact, in my opinion, there are only 4 situations for all functions.
Overloading is for contextual semantics:
For example:
void say(String name, Integer age)
void say(String name)
Of course you will say that you can define a wide range of input parameter lists to include the possibility of all subsets;
For example
void say(String name, Integer age, String address){
if(name!=null){
....
}
if(age!=null){
...
}
...
}
那么使用的时候反而增大了操作量比如
say("张三",null,null);