What is Stateless Object in Java?

前端 未结 10 1438
猫巷女王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:52

    Stateless object is an instance of a class without instance fields (instance variables). The class may have fields, but they are compile-time constants (static final).

    A very much related term is immutable. Immutable objects may have state, but it does not change when a method is invoked (method invocations do not assign new values to fields). These objects are also thread-safe.

提交回复
热议问题