web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Optional parameter in parm method

(0) ShareShare
ReportReport
Posted on by 113

hello,guys,I used to be a java developer .I have a question about the screenshot below.pastedimage1679980342840v1.pngIn 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

I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    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.

  • Suggested answer
    Tracy wang Profile Picture
    113 on at

    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.

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    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);
    }

  • Tracy wang Profile Picture
    113 on at

    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.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 503 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 434 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 278 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans