In Java, is there any disadvantage to static methods on a class?

后端 未结 14 1448
无人及你
无人及你 2020-12-03 06:37

Lets assume that a rule (or rule of thumb, anyway), has been imposed in my coding environment that any method on a class that doesn\'t use, modify, or otherwise need any ins

14条回答
  •  一生所求
    2020-12-03 07:24

    No there is no disadvantages, rather when you are not accessing any instance members in the method then there is no meaning of having it as an instance method. It is good programming skill to have it as a static method.

    and adding to that you don't have to create any instances to access these methods and thus saving a memory and garbage collecting time.

提交回复
热议问题