java里自定义类重载有什么用?
认证高级PHP讲师
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
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);
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
In fact, in my opinion, there are only 4 situations for all functions.
Overloading is for contextual semantics:
For example:
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