An instance variable, or regular field, stores data separately for each object of a class. A static field instead has one shared instance for the class, so using static where an instance variable is intended changes object-local state into shared state. section 3.11 section 3.12
The accidental static field
class Person { private static String name; public void setName(String newName) { name = newName; } public String getName() { return name; } } Here, every Person shares name. Setting one person's name changes what another person reads. Declaring name as a regular instance field keeps each object's value separate. section 3.11
This mistake can survive simple tests when objects are created and discarded one at a time. Under simultaneous use, shared state can leak between users or threads without raising an exception, creating incorrect behavior and possible privacy or security violations. section 3.11
Inspect static nonfinal fields carefully and consider whether each belongs to the class or to each object. IDE inspections can report static-field writes from instance methods, but static final does not guarantee isolation when it refers to mutable data such as a collection. section 3.11



