JDK7 the use of local variables in anonymous inner classes is not required in addition to FINAL,JDK8, but the JDK will default to final

Source: Internet
Author: User

While reading today, I saw a local inner class, which says that local internal classes can access local variables, but must be final. Because a local variable disappears after a method call, the local variable is stored in the heap with the final declaration, with the same declaration period as the inner class. But I wrote a local inner class that could access a non-final local variable, what's the matter? PS: My JDK is 8 does it have anything to do with this?


public class Jubuneibulei {
public void P (int a, int b) {

Class te{
void print () {
System.out.println (a);
}
}
New Te (). print ();
}
public static void Main (string[] args) {
New Jubuneibulei (). P (111, 222);

}
}


Not required in JDK8, but JDK will default to final

JDK7 the use of local variables in anonymous inner classes is not required in addition to FINAL,JDK8, but the JDK will default to final

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.