Record Classes
With JDK 14 record classes were introduced, which are a new kind of type declaration. They are especially useful for passing around immutable data containers. For example consider the immutable class below.
With JDK 14 record classes were introduced, which are a new kind of type declaration. They are especially useful for passing around immutable data containers. For example consider the immutable class below.
There are 2 alternatives to synchronizing objects to make sure that nothing breaks when sharing objects. Either the shared object is immutable which would lead to there never being any inconsistent states between the threads. The other alternative is you just don't have a shared state variable between threads.