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