开发者

Can a static method always be converted to an instance method?

If we can make sure the instance is the singleton, then开发者_Python百科 static method can be always converted to instance method? Is that right?


Of course a method marked as static can be converted to an instance method. Methods marked as static have to be methods that don't use any state information particular to an instance (unless the instance is passed in as a parameter). They can be rewritten the as instance methods and still not rely on state information particular to an instance (or use this instead).


You can do it of course, but you may break existing code that is calling the static method. Especially if the method is publicly visible.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜