Friday, 20 July 2018

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




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



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 comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print ...