Skip to main content

Notifications

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

  • Tracy wang Profile Picture
    Tracy wang 113 on at
    RE: Optional parameter in parm method

    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

  • Martin Dráb Profile Picture
    Martin Dráb 230,836 Most Valuable Professional on at
    RE: Optional parameter in parm method

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

  • Suggested answer
    Tracy wang Profile Picture
    Tracy wang 113 on at
    RE: Optional parameter in parm method

    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.

  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,836 Most Valuable Professional on at
    RE: x++ code question

    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.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,965 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,836 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans