1. General programming advice
This message should warn you of a potential programming error, as this is a common mistake for novice programmers who do not know the differences between static and instance variables.
However, if you can declare your real version of the removeApple static method without causing compiler errors, then most likely you should. This will take care of the warning and make it clear that this method has nothing to do with any particular instance of your class.
2. Problems associated with concurrency
Another aspect of this warning is thread safety. If you write to the static field from an instance, this opens up the possibility that you will perform parallel updates from different threads, even without sharing class instances between threads.
If you do not need thread safety for your code (which is completely normal in general), you do not need to do anything. If you need it, synchronize all field updates or use the AtomicInteger wrapper.
Personally, I would choose AtomicInteger , because this is the safest option: for other parameters, you will need to chase all field updates around the class and make sure that they are synchronized. Using AtomicInteger very simple:
private static final AtomicInteger count = new AtomicInteger();
and then use count.getAndIncrement() instead of count++ .
source share