Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [Xtend] Cannot refer to a non-final variable ... inside an inner class
[Xtend] Cannot refer to a non-final variable ... inside an inner class [message #719818] Mon, 29 August 2011 06:51 Go to next message
Nikolai Busse is currently offline Nikolai BusseFriend
Messages: 15
Registered: August 2011
Junior Member
The following xtend code
for ( n : someElememtList.map( e | e.name ).toSet ) {
	for ( e : someElememtList.filter( e | e.name == n ) ) {
		// ...
	}
}

is accepted in the xtend editor, but leads to the Java error message
Quote:
Cannot refer to a non-final variable n inside an inner lass defined in a different method

which is caused by a Java restriction on closures.
Is there a workaround for this kind of nested loops with closures in xtend?
Re: [Xtend] Cannot refer to a non-final variable ... inside an inner class [message #719824 is a reply to message #719818] Mon, 29 August 2011 07:01 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
Hi Nikolai,

this has already been fixed.

Sven
Re: [Xtend] Cannot refer to a non-final variable ... inside an inner class [message #719829 is a reply to message #719818] Mon, 29 August 2011 07:06 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi, what about
for ( n : someElememtList.map( e | e.name ).toSet ){
    val n2 = n
	for ( e : someElememtList.filter( e | e.name == n2) ) {
		// ...
	}
}

Regards Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:View AST of my grammar
Next Topic:Couldn't resolve reference to JvmOperation
Goto Forum:
  


Current Time: Thu Apr 25 02:01:23 GMT 2024

Powered by FUDForum. Page generated in 0.07214 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top