Am 29.08.2011, 22:24 Uhr, schrieb Jonathan M Davis <jmdavisp...@gmx.com>:

On Monday, August 29, 2011 12:53 Alex Rønne Petersen wrote:
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++.

I haven't used C# much, so I'm not entirely surprised if I'm wrong about that, but I'm 99.99% sure that Java allows it. I definitely remember being irritated
by it in Java.

- Jonathan M Davis

Java allows it, but gives a warning and auto-correct option to use the class reference instead, in Eclipse. That probably means that there is no justifiable use-case for it.

Reply via email to