SteelReed

Search

Search posts, questions…

OOP & DesignQuestion 4 / 42

Junior

How do static and instance members differ, and why is static mutable state dangerous in Spring?

Short answer

A static member belongs to the class (exactly one copy); an instance member belongs to each object. Static methods have no this.

shareClass: static fieldexactly one copyObject 1:own instance fieldsObject 2:own instance fieldsAll threads, requests

3 points to say:

  1. One static copy, one instance copy per object.
  2. Mutable statics are dangerous globals.
  3. Use static only for constants and pure functions.

Keep reading the deep dive

Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.