The Artima Developer Community
Sponsored Link

Legacy Design Forum
Designing with Interfaces

Advertisement

Advertisement

This page contains an archived post to the Design Forum (formerly called the Flexible Java Forum) made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Darn. :-) There's a workaround though.

Posted by Trejkaz Xaoza on January 08, 2001 at 12:43 AM

>> Is there anyway (through either inheritance or interfaces)
>> to declare an abstract static method?

> Static methods are bound at compile time based on the type of
> the reference, not at run time based on the class of the
> object. When you rewrite a static method in a subclass, you
> aren't "overridding" the superclass version of the method, but
> simply "hiding" it.

This seems really ugly. I'm assuming that when someone tries to do this, the compiler chucks a warning. Otherwise, you'd get unexpected results.

I came across the need for this same thing in my project, however, and what I ended up doing was creating an abstract factory class to correspond with the abstract class. To create objects of a new type, you override the factory class at the same time you override the other class. Static methods in the factory class ensure that only one instance of each factory class is created.




Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us