问题:
I came across some Java code that had the following structure: 我遇到了一些具有以下结构的Java代码:
public MyParameterizedFunction(String param1, int param2)
{
this(param1, param2, false);
}
public MyParameterizedFunction(String param1, int param2, boolean param3)
{
//use all three parameters here
}
I know that in C++ I can assign a parameter a default value. 我知道在C ++中可以为参数分配默认值。 For example: 例如:
void MyParameterizedFunction(String param1, int param2, bool param3=false);
Does Java support this kind of syntax? Java是否支持这种语法? Are there any reasons why this two step syntax is preferable? 有什么理由使两步语法更可取?
解决方案:
参考一: https://stackoom.com/question/4BUQ/Java是否支持默认参数值
参考二: https://oldbug.net/q/4BUQ/Does-Java-support-default-parameter-values