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
Post a Comment