I have been developing on the Microsoft. Net platform before. It cannot be instantiated in C #, and all its members are static. We generally use static classes as tool classes and directly use their attributes and methods without instantiating them,Static classes in the entire domain are unique..
When I started using Java, I found that Java static classes are generally used in the content of a class, referred to as static internal classes. In addition, this type can contain various non-static members like non-static classes, and can be instantiated at the same time. This directly subverts my perception of static classes.
Next I will compare static and non-static internal classes in Java:
public class outClass { public static class innerClass{ public innerClass(){ System.out.println("innerClass"); } } public static void main(String[] args) { //outClass a = new outClass(); innerClass b = new innerClass(); innerClass c = new innerClass(); } }
public class outClass { public class innerClass{ public innerClass(){ System.out.println("innerClass"); } } public static void main(String[] args) { outClass a = new outClass(); innerClass b = a.new innerClass(); innerClass c = a.new innerClass(); } }
Summary:
Through code, we found that non-static internal classes are affiliated to external class objects. An external class object needs to be instantiated first, and the non-static internal class can be instantiated through the external class object; static internal classes can be seen as directly affiliated external classes. This static means that the external classes are external classes rather than external class instances. External classes are unique in the process, static internal classes do not need to be unique. Multiple instances can be generated.