Is it possible to declare default argument in Java in String?

user3455638 picture user3455638 · Apr 15, 2014 · Viewed 79.6k times · Source

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?

Answer

MrLore picture MrLore · Apr 15, 2014

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

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

public void test(String name)
{

}