another design question, abstract static methods...  
Author Message
Murat Tasan





PostPosted: 2003-11-14 4:08:00 Top

java-programmer, another design question, abstract static methods... so here is another general question about java...

why can't you declare an abstract static method.

i can envision the case (indeed i have experienced the case) where one
would want an abstracct superclass, with an abstract method such that all
subclasses that implement this method make that method static.

basically, the abstract class declares an abstract method that should be
static for all implementations (for example a factory method).

this isn't allowed in java, and in the language specification, there is no
reason given as to why. it is just simply stated in a single sentence
that an abstract method cannot be static. (or it turns out even the
implemented method).

can anyone explain why this isn't allowed? (i.e. give an example that
shows the flaws that can arise from such a situation).

thanks much!

murat

--
Murat Tasan
email***@***.com
email***@***.com
email***@***.com
http://genomics.cwru.edu

 
Silvio Bierman





PostPosted: 2003-11-14 5:24:00 Top

java-programmer >> another design question, abstract static methods... Polymorphism in Java is resolved by the type of the actual object (dynamic,
runtime) the method is called against instead of the class of the reference
(static, compile time). With static methods there is no object in play, only
a class so it can only ve resolved statically during compiletime.

What calling constructs (and behaviour) do you seek for?

Silvio Bierman


 
Raymond DeCampo





PostPosted: 2003-11-16 7:19:00 Top

java-programmer >> another design question, abstract static methods... Murat Tasan wrote:
> so here is another general question about java...
>
> why can't you declare an abstract static method.
>
> i can envision the case (indeed i have experienced the case) where one
> would want an abstracct superclass, with an abstract method such that all
> subclasses that implement this method make that method static.
>
> basically, the abstract class declares an abstract method that should be
> static for all implementations (for example a factory method).
>

I do not understand what you expect to accomplish this such a method.
How do you envision it being used? Perhaps if you provide a code
sample, I could understand.

From my point of view, I do not understand the point of a static
abstract method. Static method calls are determined at compile time,
not at run time, so it is not possible for the invocation to be
polymorphic. How would one invoke a static method so that one would
expect polymorphism in any case? If you have an instance of the class,
then the method might as well be non-static. If you are using
reflection, all that matters is that the method is defined in the
current class, the base class does not matter.

Furthermore, a abstract class is allowed to have abstract instance
method because it is not possible to instantiate an instance of the
class. But one may invoke static methods of an abstract class without
an instance. So there is no mechanism to ensure that an abstract static
method is not called.

Of course, many of the points I made above are really design decisions
of the Java language designers. So I am very interested in hearing how
you response to them to make the case for the other side.

Ray