wood burning stoves 2.0*
The moose likes Java in General and the fly likes replacement of Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "replacement of "static abstrac" method?" Watch "replacement of "static abstrac" method?" New topic
Author

replacement of "static abstrac" method?

Xiaoquan Wu
Greenhorn

Joined: Dec 01, 2010
Posts: 1
A is a class, AA is a subclass of A, AAA and AAB are subclasses of AA.

The important thing to me is the hierarchical relationships of the classes, so when I use AAA , I just want it gives me a static instance with type of AAA while does not create a new instance.
I add an static method "get()"in class AAA, and the same with AAB.
To let every subclass of AA comply with such a convention, I need to define an static abstract method "get()" in class of AA. But java does not allow me to do it.

So how can I organize the classes and the methods?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19538
    
  16

You can't add such a constraint to static methods. Abstract methods are meant to be overridden, and there is no overriding with static methods.

But it wouldn't make sense to require static methods, unless you are using reflection. Without reflection you need the class name to call the static method.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Bharath Raja
Ranch Hand

Joined: Jan 21, 2009
Posts: 111
Xiaoquan Wu wrote:
need to define an static abstract method "get()" in class of AA. But java does not allow me to do it.

abstract modifier cannot co-ordinate with static modifier.
Xiaoquan Wu wrote:
A is a class, AA is a subclass of A, AAA and AAB are subclasses of AA.
So how can I organize the classes and the methods?

As per my understanding, you want to have a one generic method in class AA and, you need to override it in another classes... Am I right....
Because of your class 'AAA' and 'AAB' are subclasses of class 'AA', you can create abstract method in your class 'AA' and you can override them in both subclasses in different way. and...

welcome to the Java Ranch


Life is either daring something or nothing - Helen Keller
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: replacement of "static abstrac" method?
 
Similar Threads
Package confusion.
compilation problem
lets see if someone can solve this mistry
Generate random strings
Creating Beans by invoking static factory method