Re: Making static class ToString() not possible, why?



Zytan <zytanlithium@xxxxxxxxx> wrote:
No, it doesn't. "Override" involves polymorphism, and polymorphism
doesn't apply to static members. To convince yourself of this, try to
work out what situation you'd expect it to be invoked in.

Yes, of course, those are OOP things, and a static class is basically
just a unit of functions. I don't want to inherit anything. I just
want a ToString() method that is automatically invoked when I append
it to a string. But, for that, I want the inherited method, don't I?

But what's the "it" here? You say you want it to be automatically
invoked when you append "it" to a string, but with a static class there
*isn't* anything to append. That's the problem.

This scenario came about from me converting a struct which overrode
ToString(), into a static class. Everything converted over fine,
except the ToString(), which is used only for debugging purposes, so
it's not a big issue. I am just curious about it.

Hope that's cleared things up for you.

--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.



Relevant Pages

  • Re: Making static class ToString() not possible, why?
    ... invoked when you append "it" to a string, but with a static class there ... *isn't* anything to append. ... ToString(), into a static class. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: StringBuffer/StringBuilder efficiency
    ... The main effect of that is that you can append things like StringBuffers and CharBuffers directly, without having to toString them. ... Appending something that is not a CharSequence would capture its toStringresult as of the time of the append. ... If this was python, i'd think about modifying appended StringBuilders at runtime to intercept any attempts to modify them, to run a hook which would copy the original contents to a string for appending purposes before removing the interception code and carrying on with the append, but fortunately, such madness is not possible in java. ...
    (comp.lang.java.programmer)
  • Re: Making static class ToString() not possible, why?
    ... I don't want to inherit anything. ... invoked when you append "it" to a string, but with a static class there ... ToString() to easily print out all of its data. ... how can object.ToString be invoke on a static class? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Making static class ToString() not possible, why?
    ... Yes, of course, those are OOP things, and a static class is basically ... But, for that, I want the inherited method, don't I? ... This scenario came about from me converting a struct which overrode ... ToString(), into a static class. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: StringBuffer/StringBuilder efficiency
    ... append and toString. ... Consider that server side code is mostly just ... I began to think of children not as immature adults, ...
    (comp.lang.java.programmer)

Loading