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

后端 未结 14 1487
无人及你
无人及你 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:02

    The performance advantage is likely negligible. Use static methods for anything that's not state dependent. This clarifies the code, as you can immediately see with a static method call that there's no instance state involved.

提交回复
热议问题