Java local inner class

Source: Internet
Author: User

In the Android development just learned that the onclick of button is implemented by the way of local inner class, the concrete principle I will understand later, just encounter problems always want to know why, do not tell me this is the rule, die remember on it.

The problem is that the local inner class is defined in the method, why the variables in the method are used, only the final decoration is used?

That's what I guess.

Local inner class, no matter where the family is a class ah, define a class, you can access the members of other classes, well, I have no idea, but to access the members of the family members of the method, this is a bit too much. is not at all a scope, the function of the variable life cycle is too short, if you can access, then the function of the variables are stacked, in case the reference to the creation of the inner class object is still alive. That's a lot of embarrassment. Do not think that you are in that method of writing can be accessed, you are also a class AH. So why do you add the final modifier to the constants to access it?   Final modification is a constant, is a constant with a name, the constant is immutable, since it is a constant write final int x=3; Writing x elsewhere is the same as 3. Since the same I write 3 x, anyway x will not change. For computers, remember that x is not as direct as 3.

Java local inner class

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.