Thursday, 14 July 2016

Java alternative for C# code




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 = "");


Answer



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.


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...