Local internal class access local variable __ local inner class

Source: Internet
Author: User


Why the local internal class object accesses the local variable must be added with the final keyword.

in the final analysis, the life cycle is different.

local internal classes require GC calls to reclaim, and local variables are discarded on the stack frame stack.

so it is possible that there are local internal class objects that can access a local variable that does not exist at all, which is not allowed.

as a result, only the final keyword can be added to modify the local variables called by the local internal class object.

There is no need to add the FIANL keyword in the 1.8 version of the JDK, but it is just an illusion and will be implicitly added when compiling.

Moreover, the local variables cannot be modified in the local internal class object in 1.8, which means the implicit final semantics.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.