- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Making reference to methods or object attribute.
Wed, 2012-01-25, 01:10
Dear all,
I am looking for a mean to express something that looks like a
closure: a reference to a method or an attribute.
I know that I can express it with a closure like that:
val myRef : MyObject => MyValue = _.myMethod
My problem is that I need a mean to compare such references, which is
AFAIK not possible with standard closure.
I would like something such as:
val myRef1 : String => Int = _.length
val myRef2 : String => Int = _.length
assert(myRef1 == myRef2) // actually throw assertion error
"Thanks to Turing", comparing closure is not possible in the general
case. What I need is a way to compare trivial closures. My criteria
for triviality is when I can call them method reference (or attribute
reference).
Any clue?
Thank you
Emmanuel