The Artima Developer Community
Sponsored Link

Legacy Design Forum
Designing with Interfaces



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.


May not work always

Posted by subhash on December 12, 2001 at 11:37 PM

> There is another way to simulate static abstract methods. That is to declare an static method on the abstract super class that invokes an exception. Then override the static method on the subclasses. Then when you want to access the subclass method, use reflection to access the static method
> (eg.
> Class mccClass = this.getClass();
> Method method0 = mccClass.getMethod("staticMethod", new Class[0]);
> strPrimaryTable = (String) method0.invoke(null, new Object[0]);

> I'm not saying this is a good way to do this, but it is a way.

This workaround may not work always, particularly when you want to call a static method of a class without having one of its objects. An example is getDescription() of any utility class. I dont understand why static methods are not implemented to be polymorphic in Java or C++. That would have solved all these problems.


Sponsored Links

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