Notifications
Announcements
No record found.
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
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.
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.
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); }
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
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Martin Dráb 503 Most Valuable Professional
André Arnaud de Cal... 434 Super User 2025 Season 2
BillurSamdancioglu 278 Most Valuable Professional