static methods dont inherit (was: Constructor inheritance)  
Author Message
isamura





PostPosted: 2005-10-26 5:58:00 Top

java-programmer, static methods dont inherit (was: Constructor inheritance) "Andrew McDonagh" wrote...
: isamura wrote:
:
: snipped.
:
: > :
: > Can you clarify. Do you mean subclass can't inherit static methods either?
: >
: > ..K
: >
: Correct.
:
: Static methods don't belong to an object like normal (aka Instance)
: methods, they belong to the Class.
:
: When calling a static method you: 'Class.myStaticMethod()'
:
: there's no object, so no Vtable to use to look through.
:
This is going off-topic so I will change the thread topic.

That is puzzling since the following compiles and runs (JDK 1.42):

public static myStaticMethod(); // defined in ClassA

ClassB extends ClassA

ClassB.myStaticMethod(); // no problem

Please explain...

.K


 
Roedy Green





PostPosted: 2005-10-26 8:50:00 Top

java-programmer >> static methods dont inherit (was: Constructor inheritance) On Tue, 25 Oct 2005 17:57:42 -0400, "isamura" <email***@***.com>
wrote, quoted or indirectly quoted someone who said :

>ClassB extends ClassA
>
>ClassB.myStaticMethod(); // no problem

at the JVM level, that compiles as invokeStatic ClassA.myStaticMethod.
Allowing you to be sloppy with which level a static came from is just
a convenience of the Java language/javac.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
isamura





PostPosted: 2005-10-26 10:25:00 Top

java-programmer >> static methods dont inherit (was: Constructor inheritance) "Roedy Green" wrote ...
: On Tue, 25 Oct 2005 17:57:42 -0400, "isamura" <email***@***.com>
: wrote, quoted or indirectly quoted someone who said :
:
: >ClassB extends ClassA
: >
: >ClassB.myStaticMethod(); // no problem
:
: at the JVM level, that compiles as invokeStatic ClassA.myStaticMethod.
: Allowing you to be sloppy with which level a static came from is just
: a convenience of the Java language/javac.
:
(Argh!) I was afraid you might say that...another compiler illusion...

This is not a convenience, more like mud-patch which adds more to the confusion of an overly complex
language. I wonder if I should just throw in the towel now.

.K


 
 
Roedy Green





PostPosted: 2005-10-26 13:31:00 Top

java-programmer >> static methods dont inherit (was: Constructor inheritance) On Tue, 25 Oct 2005 22:24:51 -0400, "isamura" <email***@***.com>
wrote, quoted or indirectly quoted someone who said :

>
>This is not a convenience, more like mud-patch which adds more to the confusion of an overly complex
>language. I wonder if I should just throw in the towel now.

The really ugly compiler illusion is myObject.myStaticMethod().

Boy is that confusing! However it has some maintenance advantages.

--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.