Public class prefixtrie {<br/> // supports 7-bit chars. <br/> Private Static final int size = 128; <br/> node root = new node (); <br/> Public void put (string prefix, object value) {<br/> node current = root; <br/> //.... <br/>}< br/> Public object get (string key) {<br/> node current = root; <br/> //.... <br/>}< br/> // This is the static internal class. See the reference description below <br/> static class node {<br/> object value; <br/> node [] Next = new node [size]; <br/>}< br/>}
Reference http://webservices.ctocio.com.cn/wsdev/428/9058928.shtml:
Purpose and restriction of parsing static internal classes
During the development process, the most used internal classes are non-static members. However, under specific circumstances, static internal classes can also play their unique roles.
1. Use of static internal classes.
When defining an internal class, you can add a permission modifier static before it. This internal class is changed to a static internal class. However, for various reasons, such as restrictions on use
And other factors (the specific restrictions, I will elaborate in the following content), not a lot of practical work. But it does not mean that it has no value. In some special cases, this static internal
Class. For example, during code program testing, if you set a primary method in each Java source file (the primary method is the entry to an application and must have it), there will be a lot
External code. In addition, the code of this main program is only a form for java files, and does not need this main method. However, it is absolutely impossible to lose the master method. In this situation
You can write the primary method to the static internal class without setting a similar primary method for each Java source file. This is very useful for code testing. In some medium and large applications
Sending is a common technical means. For this reason, although this static internal class is not very common, it must be mastered by developers. It may play a significant role at a critical moment.
Maybe.
Ii. Restrictions on the Use of static internal classes.
Defining an internal class as a static class is basically the same as defining other classes as static classes, and the reference rules are also basically the same. However, the details are still quite different. Specifically, there are several main points to attract the attention of developers.
One is the definition of static members (including static variables and static members. Generally, if an internal class is not defined as a static internal class, when defining a member variable or member method,
Cannot be defined as static member variables or static member methods. In other words, static members cannot be declared in non-static internal classes. For example, an internal class is defined in a student class.
Age. If the class is not modified using the static keyword, that is, it is not defined as a static class, if the internal class uses the static keyword to modify a member method or member
Variables are not allowed. It won't work during compilation. Therefore, program developers must note that only by modifying an internal class to a static class can static member variables and member methods be defined in this class. This
Is a feature of static internal classes. It is precisely for this reason that, sometimes, with this static internal class missing, a lot of work cannot be done. In other words, it is necessary to bypass a large circle to meet the needs of a user. This is also
It is an important reason why static internal classes exist.
Second, there are large restrictions on member references. Generally, non-static internal classes can access member variables and member methods in external classes at will. Even if these member methods are modified
Private (Private member variables or methods), and its non-static internal classes can be freely accessed. It is a non-static internal Class privilege. Because other classes cannot access the member variables defined as private
Or the method. However, if an internal class is defined as static, there will be many restrictions when Silver uses the member method of the external class or the member variable. If you cannot access the outside from objects of static internal classes
Non-static members of the class (including member variables and member methods ). What does this mean? If two variables are defined in the external class, one is non-static and the other is static. So in the static internal class
Can only reference static variables in the external class, regardless of the member method or other places, but cannot access non-static variables. In static internal classes, you can define static methods (or
Static methods can be defined in the internal class of the State), and the members of the External class can be referenced in the static method. However, no matter where the internal class is referenced, there is one thing in common, that is, only the static member in the external class can be referenced.
Method or member variable. Non-static member variables and member methods cannot be accessed in static internal classes. This is the maximum usage limit for static internal classes. This is not found in common non-static internal classes.
Restricted. This also determines that static internal classes are only used in some specific scenarios. Its application scope is far from as wide as non-static internal classes.
Third, when creating a static internal class, you do not need to bind the instance of the static internal class to the instance of the external class.
Generally, when creating a member internal class in a class, there is a mandatory rule that the instance of the internal class must be bound to the instance of the external class. That is to say, before creating an internal class, you must first create an external class.
Use the New Keyword to create the object of this internal class. In this case, if an internal class object is initialized from an external class, the internal class object will be bound to the external class object. That is to say, normal non-static
Objects of internal classes are attached to external class objects. However, if a member developer creates a static internal class, this is another matter. Generally, when a programmer defines a static internal class
You do not need to define instances bound to external classes. That is to say, to define a static internal class in an external class, you do not need to use the keyword new to create an instance of the internal class. Create a static class
Internal objects do not require external class objects. The specific reason is as follows. Generally, developers do not need to understand this details, but remember to have this rule. When defining static internal classes, do not
To make a superfluous mistake.
From the above analysis, we can see that static internal classes are quite different from non-static internal classes. Generally, programmers can understand that non-crystalline internal class objects are implicitly in the external class.
Saves a reference and points to the external class object that creates it. With this understanding, developers must remember the differences between static and non-static internal classes. For example, whether static member methods and member changes can be created
Quantity (static internal classes can create static members, not static internal classes) limitations on access to members of external classes (static internal classes can only access static member variables and member methods in external classes, rather than static
The internal class can access static or non-static external class member methods and member variables ). These two differences are the biggest differences between static internal classes and non-static external classes. They are also the reason why static internal classes exist.
. After understanding the difference, the program developers also need to know under what circumstances should they use static internal classes. For example, during program testing, to avoid writing the main method in each Java source file
Code, you can write the main method into the static internal class, to reduce the amount of code writing, make the code more concise.
In short, static internal classes are a special class in the Java language, which is very different from common static classes and non-static internal classes. As a program developer, you must know
And use the appropriate classes in the appropriate place in the actual work. But in general, the usage frequency of static internal classes is not very high. However, in some cases, if this internal static class is not available
The opposite effect is achieved.