3

I have a function with the following declaration in c#. It allows me call the function without providing a value for the expectedDisplayValue variable. The function automatically initializes the variable to "". I want a similar declaration in java. How can I do that?

public bool VerifyControlState(string identifier,string controltype, ButtonProperty buttonProperty, string expectedDisplayValue = "");
azurefrog
  • 10,785
  • 7
  • 42
  • 56
  • You can't do that in Java, but see [this question](http://stackoverflow.com/questions/997482/does-java-support-default-parameter-values) for alternatives. – azurefrog Jun 11 '15 at 05:54
  • Dear java is not a mouth feeder like c#... But you can achieve the above scenario with the help of function overloading. – Shailesh Yadav Jun 11 '15 at 06:04

1 Answers1

4

The structure of Java handles this through function overloading. Basically, create a function that doesn't have expectedDisplayValue as a parameter and that function would call VerifyControlState (identifier, controltype, buttonProperty, "");

See the Does Java support default parameter values? question for more details.

Community
  • 1
  • 1
Eddy
  • 76
  • 2