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

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

    In order to call the static methods you don't need to create class objects. The method is available immediately.

    Assuming the class is already loaded. Otherwise there's a bit of a wait. :-)

    I think of static as a good way to separate the functional code from procedural/state-setting code. The functional code typically needs no extension and changes only when there are bugs.

    There's also the use of static as an access-control mechanism--such as with singletons.

提交回复
热议问题