November 7, 2020 I didn't understand Java's static final and static import, so I'll summarize the static modifiers.
Used to access methods and variables directly without instantiating the class. Methods with static are called static methods, and variables are called static variables.
In Java, static class is used in the inner class (inner class) that defines the class in the class. The inner class can access members such as variables of the outer class. Adding the static modifier to the inner class allows access only to the static members of the outer class.
A static method is a method that can be called without creating an instance using new by adding a static modifier to the method, and it is not necessary to create an instance every time the method is called, so the code can be written short. ..
A static variable can be accessed by adding the static modifier to the variable without instantiating the class that contains the variable. A static variable is a value shared by all instances created from that class, so it can be used like a global variable.
static final can be used when you don't want the value of a variable to change, and can be a constant whose value cannot be changed </ b>. There are methods such as initializing multiple constants using a static initializer and using List and Map as constants.
static import is a function to simplify the reference of static members of external classes. Calling methods and constants is simplified, allowing you to write processing in concise code.
[Introduction to Java] Summary of how to use static modifiers
Recommended Posts