When to make a method static?

后端 未结 7 527
忘掉有多难
忘掉有多难 2021-01-30 02:04

I\'d like to know how people decide whether to define a method as static. I\'m aware that a method can only be defined as static if it doesn\'t require access to instance fields

7条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-30 02:45

    Non static by default, static when I need the functionality to be available from at least two different classes, and I don't want to waste a constructor.

    ps. Archimedes rules!

提交回复
热议问题