I have a class, for example:
public class A{
private final int number;
public A(int number){
this.number = number;
}
}
Quesiton is, I want to update number
time by time, and I must make A object stateless, which means nubmer
has to be final. My friend suggested my to use AtomicInteger
class, but I don't know how to make it work.
AtomicInteger are thread safe, you should use it like this :
But if you want to make something final you shouldn't use AtomicInteger, and final must be known at compile time so your solution is encapsulation, something like you did :
For a stateless object I think you misunderstood what it means.