开发者

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

开发者 https://www.devze.com 2023-02-05 13:23 出处:网络
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

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

精彩评论

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

关注公众号