What is the gain from declaring a method as static

后端 未结 9 564
别跟我提以往
别跟我提以往 2020-12-07 10:35

I\'ve recently been looking through my warnings in Eclipse and come across this one:

\"static

9条回答
  •  萌比男神i
    2020-12-07 11:25

    See Samuel's answer on how the scope of the method changes. I guess, this is the main aspect of making a method static.

    You also asked about performance:

    There might be a tiny performance gain, because a call to a static method does not need the implicit "this" reference as parameter.

    However, this performance impact is really tiny. Therefore, it's all about the scope.

提交回复
热议问题