-3

I want to make a method as follows:

private static String methodName(String name, boolean failOnMissing = true) {
    ...
}

I'm getting the following error:

',' Expected

Eran
  • 387,369
  • 54
  • 702
  • 768
  • Thats not going to work in Java – John Kane Mar 06 '18 at 15:09
  • 1
    are you coming from c++? – SomeDude Mar 06 '18 at 15:09
  • 1
    Check this: https://stackoverflow.com/questions/997482/does-java-support-default-parameter-values – CrazySabbath Mar 06 '18 at 15:09
  • No. You A) want to turn to the [help] to learn how/what to ask here, and B) you want to do that prior research thing. Dont assume that a language should have a feature (because you prefer it to be that way). Rather turn to the books and look what exactly the language has to offer. – GhostCat Mar 06 '18 at 15:10

1 Answers1

3

The are no default values for method arguments in Java. You can use method overloading instead.

private static String methodName(String name) {
    return methodName(name,true);
}

private static String methodName(String name, boolean failOnMissing) {
    ...
}
Eran
  • 387,369
  • 54
  • 702
  • 768