Why can't the internal class defined in the method only access local variables of the final type in the method?

Source: Internet
Author: User
Class inout {string STR = new string ("between"); Public void amethod (final int iargs) {int it315 = 10; Class bicycle {public void sayhello () {system. out. println (STR); system. out. println (iargs); system. out. println (it315); // compilation error: inout. java: 13: local variable it315 is accessed from within inner class; needs to be declared final }}}}

Java stipulates that the internal class can only access the member variables in the external class and cannot access the variables defined in the method. To access the variables in the method, declare the variables in the method as final (constant) because this can render the variable, it is equivalent to being defined externally rather than in the method.

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.