What is the gain from declaring a method as static

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

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

\"static

9条回答
  •  Happy的楠姐
    2020-12-07 11:34

    Well, the Eclipse documentation says about the warning in question:

    Method can be static

    When enabled, the compiler will issue an error or a warning for methods which are private or final and which refer only to static members

    I think it pretty much says it all. If the method is private and final and only refers to static members, the method in question might just as well be declared static and by this, make evident that we only intend to access static content from it.

    I honestly don't think there is any other mysterious reason behind it.

提交回复
热议问题