What is Stateless Object in Java?

前端 未结 10 1449
猫巷女王i
猫巷女王i 2020-11-30 21:32

Currently I\'m reading \"Java concurrency in practice\", which contains this sentence:

Since the action of a thread accessing a stateless object can\'

10条回答
  •  天涯浪人
    2020-11-30 21:51

    Just a clarification. You can consider your class as stateless in the way that is stated before, even when it has an instance variable as far as this variable is final AND immutable.

    If the instance variable is just final but mutable, a List of Strings in example, yes the variable's reference can not be changed but the contents of the List and thus the state of the class can be changed.

提交回复
热议问题