Java 支持默认的参数值吗?

I came across some Java code that had the following structure:

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. For example:

void MyParameterizedFunction(String param1, int param2, bool param3=false);

Does Java support this kind of syntax? Are there any reasons why this two step syntax is preferable?

转载于:https://stackoverflow.com/questions/997482/does-java-support-default-parameter-values

查看全部
csdnceshi50
三生石@
2009/06/15 18:04
  • default-value
  • java
  • methods
  • method-overloading
  • parameters
  • 点赞
  • 收藏
  • 回答
    私信

0个回复