Call an object method: Difference between revisions
Replace println() with print(); replace output "syntaxhighlight" tag with "pre" tag
Jazzedpineda (talk | contribs) (Omit Plain English) |
(Replace println() with print(); replace output "syntaxhighlight" tag with "pre" tag) |
||
Line 345:
Example example = new Example("hello!");
String methodResult = example.toString(); // <-- call a method
console.
// Int funcResult = example.oneMoreThan(12); // <-- compiler error
Int funcResult = Example.oneMoreThan(12); // <-- call a function
console.
// methods and functions are also objects that can be manipulated;
Line 355:
Method<Example, <>, <String>> method = Example.toString;
function String() func = method.bindTarget(example);
console.
// by default, a method with target T converts to a function taking a T;
// Ecstasy refers to this as "Bjarning" (because C++ takes "this" as a param)
val func2 = Example.toString; // <-- type: function String()
console.
// the function is just an object, and invocation (and in this case, binding,
Line 367:
val func3 = Example.oneMoreThan; // <-- type: function Int(Int)
val func4 = &func3(13); // <-- type: function Int()
console.
}
}
</syntaxhighlight>
{{out}}
<pre>
Result from calling a method: "This is an example with text=hello!"
Results from calling a function: 13
Line 379:
Calling a Bjarne'd function: "This is an example with text=hello!"
Calling a fully bound function: 14
</pre>
=={{header|Elena}}==
|