What do you mean by static methods?
If a method called from outside the class and it wasn’t declared static, it would have to be qualified (uselessly) with an object.
Even when used within the class, there are good reasons to define a method as static when it could be.
– Documentation : Anyone seeing that a method is static will know how to call it. Similarly, any programmer looking at the code will know that a static method can’t interact with instance variables, which makes reading and debugging easier.
– Efficiency : A compiler will usually produce slightly more efficient code because no implicit object parameter has to be passed to the method.
Recent Comments