Should Java methods be static by default?

后端 未结 23 1240
既然无缘
既然无缘 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:54

    If foo() doesn't have anything to do with Object A then why is the method in there?

    Static methods should still be relevant. If there isn't anything going on then why have you written a method that has no association with it?

提交回复
热议问题