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.
精彩评论