Forcing Java lambda expressions to capture non-final variables in Java -


is possible have lambda expression capture variable not final?

i know code work if capture them, have create new variable copies non-final variable want pass lambda expression.

final someclass otherobj;  for(int = 0; < 10; i++) {     int = i;     someobject.method(() -> otherobj.process(a, a+1)) } 

i'd pass in 'i' instead of having create new temporary variable.

you can try java8,

intstream.range(0, 10).foreach(i ->{    someobject.method(() -> otherobj.process(i, i+1)) }); 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -