Call an object method: Difference between revisions
Content added Content deleted
mNo edit summary |
|||
Line 359: | Line 359: | ||
Calling a method or function in Ecstasy follows roughly the same conventions as in Java and C#, but in order to prevent certain types of bugs, Ecstasy explicitly disallows calling a function <i>as if it were a method</i>. |
Calling a method or function in Ecstasy follows roughly the same conventions as in Java and C#, but in order to prevent certain types of bugs, Ecstasy explicitly disallows calling a function <i>as if it were a method</i>. |
||
<syntaxhighlight lang="java"> |
<syntaxhighlight lang="java"> |
||
module CallMethod |
module CallMethod { |
||
⚫ | |||
/** |
/** |
||
* This is a class with a method and a function. |
* This is a class with a method and a function. |
||
*/ |
*/ |
||
const Example(String text) |
const Example(String text) { |
||
{ |
|||
@Override |
@Override |
||
String toString() |
String toString() { // <-- this is a method |
||
{ |
|||
return $"This is an example with text={text}"; |
return $"This is an example with text={text}"; |
||
} |
|||
static Int oneMoreThan(Int n) |
static Int oneMoreThan(Int n) { // <-- this is a function |
||
{ |
|||
return n+1; |
return n+1; |
||
} |
|||
} |
} |
||
⚫ | |||
void run() |
void run() { |
||
{ |
|||
@Inject Console console; |
@Inject Console console; |
||
Line 407: | Line 402: | ||
val func4 = &func3(13); // <-- type: function Int() |
val func4 = &func3(13); // <-- type: function Int() |
||
console.print($"Calling a fully bound function: {func4()}"); |
console.print($"Calling a fully bound function: {func4()}"); |
||
} |
|||
} |
} |
||
} |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||