java - Lambdas: local variables need final, instance variables don't -


in lambda, local variables need final, instance variables don't. why so?

the fundamental difference between field , local variable local variable copied when jvm creates lambda instance. on other hand, fields can changed freely, because changes them propagated outside class instance (their scope whole outside class, boris pointed out below).

the easiest way of thinking anonymous classes, closures , labmdas variable scope perspective; imagine copy constructor added local variables pass closure.


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -