If I have an Enum as a helper in a Java class, is there any way to refer to that Enum outside of the class it’s helping?
Basically, what I have is this:
class Account extends MyClass {
HashMap<Property, String> property = new HashMap<Property, String>();
public Account() {
}
public enum Property {
USERID,
PASSWORD;
}
}
I want to be able to access the Property enum outside of the Account class.
The reason I want to do this is because this is a subclass of a another, and I want to be able to access the properties of a given subclass without referring to a unique enum name (i.e.: without referring to each one as, say, AccountProperty or ResearchProperty or TaskProperty etc).
Your enum is public so you just can use
Account.Propertyto access it from outside theAccountclassEDIT :
If I got what you need, you’d like to do something like
where Product is
and you want to do this in your
MyClass.The problem is that both the two lines require an import and you can’t import two classes with the same name, so the only solution is to do something like this
I guess that you’ve got to deal with the
instanceofto use the rightPropertyenum for each class, as there’s no way to extend an enum!