[JAVA] static variable

I studied Java static variables.

The correct use of Java static variables 1, constant 2. Shared variables used only within the class It seems that it is.

    1. To use it as a constant, you can add final static.

final static int i = 10;

It's like that. Also, in a concrete example, it seems that jdk itself is a List because java.util.Collections.EMPTY_LIST is specified as final static.

  1. Shared variables used only within the class

However, you can set the access modifier to private so that it can be referenced and updated only from within that class. That's right

public class Hello{
    public static final String Message = "Hello World";
    private static String innnerMessage;
}

However, it seems that it is better to avoid sharing variables within the class as much as possible.

I studied below. http://tkmtys.hatenablog.com/entry/2015/10/11/033349

Recommended Posts

static variable
variable
static
Java static
About static
static modifier
ruby constant variable
java array variable
Java static story
Static uncle's counterattack
Java variable scope (scope)
Variable / immutable object
java variable declaration
variable and method
Java variable scope
[Introduction to Java] Variable scope (scope, local variables, instance variables, static variables)