Should Java methods be static by default?

后端 未结 23 1284
既然无缘
既然无缘 2020-12-04 09:24

Say you\'re writing method foo() in class A. foo doesn\'t ever access any of A\'s state. You know nothing else about what foo does, or how it behaves. It cou

23条回答
  •  无人及你
    2020-12-04 09:53

    If it does nothing with objects of this class, but actually belong to this class (I would consider moving it elsewhere), yes it should be static.

提交回复
热议问题