Often used as a class constant
private static final
Survey results on what it means to add static in. This is useful when you want to give a name to each instance.
public class Sample {
private static final String A1 = "A1";
// private static final String A1;Is a compilation error
private final String A2;
Sample() {
this.A2 = "A2";
}
public static void main(String[] args) {
new Sample();
}
}
By making constants static, you will have only one in the class instead of each instance, and memory can be saved.
Quote: [Java] What is private static final? 16bit!
Recommended Posts