In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "the principle and usage example analysis of Java local inner class". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor to take you to learn the "Java local internal class principle and usage example analysis"!
A little bit of eye contact
If an inner class is defined in a method, then the inner class is a local inner class, and the local inner class is valid only in the method.
Because the local inner class cannot be used outside the methods of the outer class, the local inner class cannot be modified with the control conformance static modifier.
If you need to define a variable, create an instance, or derive a subclass with a local inner class, it can only be done in the same method as the local inner class.
Two code
Public class LocalInnerClass {public static void main (String [] args) {/ / define the local inner class class InnerBase {int a;} / define the local inner class subclass class InnerSub extends InnerBase {int b;} / / create an object of the local inner class InnerSub is = new InnerSub (); is.a = 5; is.b = 8; System.out.println ("the an and b instance variables of the InnerSub object are:" + is.a + "," + is.b);}} "
Three operation
The an and b instance variables of the InnerSub object are: 5pm 8
Four instructions
After compilation, three files, LocalInnerClass.class, LocalInnerClass$1InnerBase.class, and LocalInnerClass$1InnerSub.class, are generated. The reason why the local inner class has numbers is that there may be more than two local internals of the same name (in different methods) in the same class.
The local internal scope is too small to facilitate multiple reuse, so local internal classes are rarely used in development.
At this point, I believe that everyone has a deeper understanding of the "Java local internal class principle and usage example analysis", might as well come to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.