The role of the inner class
Java is a single inheritance, which implements multiple inheritance through an interface. When there is only an abstract class or a concrete class, and there is no interface, you can implement multiple inheritance with an anonymous inner class.
Internal class classification
- Ordinary inner class
- Anonymous inner class
- Nested classes
Anonymous inner class
public class Demo { prvivate int n; public E make() { return new E() {...}; }}
The return statement of the Make method means that the object is instantiated from the method body and then transformed upward into a reference to the base class E.
This reference must be decorated if we want to use the member reference of an external class inside the method body of an anonymous inner class final .
There are differences between multiple inheritance and interfaces through anonymous inner classes: instantiated objects resulting from multiple interface inheritance can be transformed upward into multiple target interfaces, whereas instantiated objects produced by anonymous inner classes can only be transformed upward into a single base class reference. That is, the multiple inheritance of an anonymous inner class is a subclass to a base class, and an interface is a subclass to multiple interfaces.
Nested classes
The inner class declared with static, which is often referred to as a nested class.
Objects whose perimeter classes are not required to create nested class objects, and non-static perimeter class objects cannot be accessed from objects in nested classes.
Java Internal classes