0

I have a method with an optional string parameter. The default string value for this parameter needs to be created based on one of the other inputs. So I can't define the default value directly in the method parameters. I could set the default value to null and then check for that, however if the string provided was actually null this could create some difficult situations to debug. Is there a way to check if a parameter was actually provided?

  public static method(String input1, String input2 = null)
  {
      if (noSecondParameter())
      {
          input2 = getDefaultInput(input1)
      }
  }
huysentruitw
  • 26,177
  • 9
  • 85
  • 125
EJS
  • 941
  • 4
  • 12
  • 26

1 Answers1

9

Use member overloading:

public static method(String input1)
{
}

public static method(String input1, String input2)
{
}
huysentruitw
  • 26,177
  • 9
  • 85
  • 125