File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Issues With Enum Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Issues With Enum" Watch "Issues With Enum" New topic

Issues With Enum

SanjayR Jain
Ranch Hand

Joined: Mar 05, 2009
Posts: 43
I have a ten enum. One of them is as below:

And for the ten enum classes I have ten other classes in which each of one used.
One of them is as below :

Now I have a Super class and all my ten classes extends to this super class :

// Super Class

I dont want to add getData method to each in every my suclass for getting data.So I want that in any way I can return the enum to super class and in super class I use for over enum.values();
But I didnt find a way to return a enum from a method.
May be this is not poosible.So please help me out
Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

An enum is a type, so you cannot return it like this. You can only return a concrete implementation of it. You could return the values instead :

And use return Type.values() in your concrete classes.

[My Blog]
All roads lead to JavaRanch
Rob Spoor

Joined: Oct 27, 2005
Posts: 20279

Note that covariant return values are allowed. So if the abstract super class method returns Enum[] the concrete subclass can return Type[].

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: Issues With Enum
It's not a secret anymore!