Re: Why can't static methods be overridden?
From: Owen Jacobson (angstrom_at_lionsanctuary.net)
Date: 09/22/04
- Previous message: juicy: "Re: writeObject and readObject problem"
- In reply to: bernd_no_junk_at_hotmail.com: "Why can't static methods be overridden?"
- Next in thread: bernd_no_junk_at_hotmail.com: "Re: Why can't static methods be overridden?"
- Reply: bernd_no_junk_at_hotmail.com: "Re: Why can't static methods be overridden?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 22 Sep 2004 07:29:32 GMT
On Tue, 21 Sep 2004 22:10:19 -0700, bernd_no_junk wrote:
> Quite often I have a hierarchy of classes where
> I want a specific accessor method to be
> present in all classes. Therefore I specify
> it in the base class. But the information
> that this function returns only depends on the
> actual class, so it should static, shouldn't it?
>
> I ran into the neccessity to do so sometimes
> during design and started wondering why Java
> actually forbids it.
>
> Is there a specific OO reason?
This seems to be related to the recent discussion about invoking static
methods through instances. Consider if derived classes could override
static (class-scope) methods:
class A {
static void something () {}
}
class B extends A {
static void something () {}
}
...
A anA = new B ();
anA.something (); // This is valid, modulo B.something ()'s existence
Which 'something' should be invoked, here? Currently the rules say that
A.something should be invoked, but if it were possible to override
something in derived classes you can bet people would then want to be able
to call derived static methods through base class references, which I can
only assume the Sun guys feel is much less straightforward than the
current mechanism.
For what it's worth I agree with them.
-- Some say the Wired doesn't have political borders like the real world, but there are far too many nonsense-spouting anarchists or idiots who think that pranks are a revolution.
- Previous message: juicy: "Re: writeObject and readObject problem"
- In reply to: bernd_no_junk_at_hotmail.com: "Why can't static methods be overridden?"
- Next in thread: bernd_no_junk_at_hotmail.com: "Re: Why can't static methods be overridden?"
- Reply: bernd_no_junk_at_hotmail.com: "Re: Why can't static methods be overridden?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|