55 Bound method references
counter.add becomes a function value bound to that particular counter. Invoking add(2) updates the same object's field.
norm
class Counter {
Integer value
Integer add(Integer amount) {
value = value + amount
return value
}
}
main() {
Counter counter = Counter(value: 10)
Integer add(Integer amount) = counter.add
printLine(add(2))
printLine(counter.value)
}Expected output:
text
12
12Try it: Create another counter and bind its add method separately.
Precise rules: Reference.