Dashboard > Mantra > ... > Classes > Methods
  Mantra Log In | Sign Up   View a printable version of the current page.  
  Methods
Added by Terence Parr, last edited by Terence Parr on Nov 03, 2007  (view change)
Labels: 
(None)

class T {
    method1() { ... } // no return value
    type0 method2(type1 a, type2 b,...) { ... } // return a type0 object
}

Only methods that have an explicit return type can return a value. If
you do not have a return statement, Mantra adds return null; for you
at the end.

Methods can have zero or more arguments.

Methods may be overloaded based on number of arguments (but currently
not according to type like you can in Java):

class string {
    ...
    list split() {...}
    list split(regex) {...}
}

Like Java, toString, equals are "special" methods.

You can define class methods using static:

class Math {
    static int add(int a, int b) { return a+b; }
}
>>
Site powered by a free Open Source Project / Non-profit License (more) of Confluence - the Enterprise wiki.
Learn more or evaluate Confluence for your organisation.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.1 Build:#806 May 06, 2007) - Bug/feature request - Contact Administrators