문제

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?

도움이 되었습니까?

해결책

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

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

public void test(String name)
{

}

다른 팁

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

public void test() {
    test("exampleText");
}
public void test(String name) {
    //logic here
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top