Is it possible to declare default argument in Java in String? [duplicate]

牧云@^-^@ 提交于 2019-11-30 16:23:33

问题


Is it possible to use default argument in the method with String. The code is shown below:

public void test(String name="exampleText") {
}

The code above generate error. Is it possible to correct it?


回答1:


No, the way you would normally do this is overload the method like so:

public void test()
{
    test("exampleText");
}

public void test(String name)
{

}



回答2:


No, it is not. However, the following is possible:

public void test() {
    test("exampleText");
}
public void test(String name) {
    //logic here
}


来源:https://stackoverflow.com/questions/23093327/is-it-possible-to-declare-default-argument-in-java-in-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!