Overloading static methods

Alex Rønne Petersen xtzgzorex at gmail.com
Mon Aug 29 12:53:26 PDT 2011


On 29-08-2011 19:47, Jonathan M Davis wrote:
> On Monday, August 29, 2011 07:44 Steven Schveighoffer wrote:
>> My opinion is that static methods should *not* be callable from an
>> instance, you should need typeof(instance).staticMethod. The current
>> allowance is misleading.
>
> Yeah. I don't know why it's allowed. I think that C++, Java, and C# all allow
> it too, but I've always thought that it was a bad idea in all of those
> languages. I don't see a problem being able to call a static method inside of
> its class without giving the class name (if you had both a static and non-
> static method with the same name, then you could simply require that either
> the type name or this be use), but it strikes me as very lax to allow a static
> method to be called with an instance. That's definitely one of the little
> things that I'd love to see changed. It's not the end of the world if it
> isn't, but I see no cons to changing it other than the possibility of breaking
> code (which was arguably bad code to begin with).
>
> - Jonathan M Davis

C# doesn't and I'm fairly sure Java doesn't either (though I'm certainly 
no Java expert). Overall, I think this entire "call static method on 
instance" deal comes from C++.

- Alex


More information about the Digitalmars-d mailing list