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 = "");
2
  • You can't do that in Java, but see this question for alternatives. Commented Jun 11, 2015 at 5:54
  • Dear java is not a mouth feeder like c#... But you can achieve the above scenario with the help of function overloading. Commented Jun 11, 2015 at 6:04

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.