> Longs are immutable. Maybe try java.util.concurrent.atomic.AtomicLong,
> will save you the trouble of having to implement an own wrapper.
> > Longs are immutable. Maybe try java.util.concurrent.atomic.AtomicLong,
> > will save you the trouble of having to implement an own wrapper.
>
> Thanks, that saves a lot of hassle.
Keep in mind that AtomicLong has extra functionality to deal with
thread-safety. If you know you don't need thread safety, I would
suggest writing your own wrapper.
More specically, I'm assuming your "long" value actually has a
semantic meaning. For instance, numberOfSheep.
public class SheepCounter {
private long numberOfSheep;
public Long getNumberOfSheep() {
return numberOfSheep;
}
public void count() {
numberOfSheep++;
}
public void setNumberOfSheep(long numberOfSheep) {
this.numberOfSheep = numberOfSheep;
}
}
Avoid primative obsession where it makes sense. You might find that
the class can start taking on more behavior, and you'll end up with
better design.