I have seen that sometimes methods in a class that do not depend on the instance state are marked as static
. I find that it makes it quite clear in that it advertises that 'this method is independent of instance state'. It is easy to skip that method entirely when reviewing for chances of inconsistent state.
But, the problem with marking the method static is that static methods can't be inherited or overridden.
Something like this is discussed here: Does it make sense to have a non static method which does not use an instance variable?
Would it make sense to have an annotation to declare that a non-static method is state-independent? Then the compiler could verify that it uses only other state-independent methods.
Is there any such feature in the pipeline?