An initializer initializes a variable immediately after a class is initialized or an instance is created. If it is a class variable, it will be executed when the class is initialized, and if it is an instance variable, it will be executed when the instance is created.
This is used to initialize class variables when the class is loaded. Class variables exist without being instantiated and can be used, so initialization is required. It is usually done by initialization substitution, but it is also effective when a large number of elements need to be initialized.
For the initializer ・ Static initializer -Instance initializer There are two.
Recommended Posts