No access to inner methods and members from a lambda?

33 views
Skip to first unread message

Christian Vogel

unread,
Apr 9, 2014, 9:06:18 AM4/9/14
to xtend...@googlegroups.com

Hi,


Say that I create an abstract class with a single abstract method, but with other members:


import org.junit.Test

abstract class Performer {

def perform() { println('hello!') 

def abstract void hello()

}


And I try to create an instance by using a lambda [ | ] expression, I seem to be unable to access other members of this class ( perform() in this test case):

import org.junit.Test

class TestAbstract {

@Test def void test() {

work [| perform ] // gives error, perform is not accessible..

}

def void work(Performer p) {

p.hello

}


}


Why is this? The member is there in the created anonymous class in the created source code after all.


Christian

Christian Vogel

unread,
Apr 9, 2014, 9:07:39 AM4/9/14
to xtend...@googlegroups.com

To answer my own question, is it because the ‘this’ of the created lambda is set to the current instance, to allow for closure programming?

--
You received this message because you are subscribed to a topic in the Google Groups "Xtend Programming Language" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/xtend-lang/lJfCQRj9eHo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to xtend-lang+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sebastian Zarnekow

unread,
Apr 9, 2014, 9:09:57 AM4/9/14
to xtend...@googlegroups.com
self.perform will do the trick. 'this' points to the enclosing instance where 'self' is the current anonymous lambda instance.



You received this message because you are subscribed to the Google Groups "Xtend Programming Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xtend-lang+...@googlegroups.com.
signature.asc

Christian Vogel

unread,
Apr 9, 2014, 9:10:24 AM4/9/14
to Sebastian Zarnekow, xtend...@googlegroups.com

great! thanks

Reply all
Reply to author
Forward
0 new messages