hello,guys,I used to be a java developer .I have a question about the screenshot below.In the java language, the input to a method is usually not assigned the way I've labeled it in red, so if I can, in the java language it doesn't have to be assigned backwards the way I labeled it in blue. Because these two variables are already equal. Can you just return. Can someone explain to me the reason for this? Although I know that if I don't write it that way, the argument has no value
yes,Your example is very good, and I can understand it very well, because it is consistent with other object-oriented languages, giving this parameter a default value
Yes, you're right in this particular example. But optional parameters aren't limited to parm methods - you can use them in other method to. For example:
public EcoResDescription productDescription(LanguageId _languageId = SystemParameters::getSystemLanguageId()) { return EcoResProductTranslation::getDescriptionOrDefaultDescription(this.RecId, _languageId); }
hi,Martin,i have solved this question.This is a special way of writing property methods in X++.anyway,Thank you for your reminding. I will pay attention to the way of asking questions next time.
Hi Tracy "x++ code question" isn't a good title of a thread, because it says nothing about the topic. Please try harder to give a name to your question. Also, you selected a wrong category: it should be Development / Customization / SDK, not Other.
The flaw in your thinking is in "these two variables are already equal". They may be equal, but they don't have to be. The optional value of the parameter is assigned only if the method is called without a parameter. Like this: this.parmNum().
If you provide a value, like this.parmNum('abc'), the optional parameter isn't used and _num variable will contain 'abc'.
In Java, you can use method overloading instead of optional parameters.
André Arnaud de Cal...
291,965
Super User 2025 Season 1
Martin Dráb
230,836
Most Valuable Professional
nmaenpaa
101,156