Have you looked at the methods of an enum? Which of those could help to iterate through the values?
// Yes the hint is intentionally.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Mike Simmons
Ranch Hand
Joined: Mar 05, 2008
Posts: 2778
2
posted
0
Errr, the method Jon needs isn't really listed under Enum, since it's a static method attached to each individual Enum subclass. Jon, you need to follow the link to JLS 8.9 where they talk about the valueOf() and values() methods.
Mike Simmons wrote:Errr, the method Jon needs isn't really listed under Enum, since it's a static method attached to each individual Enum subclass. Jon, you need to follow the link to JLS 8.9 where they talk about the valueOf() and values() methods.
"ordinal
public final int ordinal()
Returns the ordinal of this enumeration constant (its position in its enum declaration, where the initial constant is assigned an ordinal of zero). Most programmers will have no use for this method. It is designed for use by sophisticated enum-based data structures, such as EnumSet and EnumMap.
Returns:
the ordinal of this enumeration constant"
Wouter Oet wrote:Have you looked at the methods of an enum? Which of those could help to iterate through the values?
// Yes the hint is intentionally.
Excuse me?
Mike Simmons
Ranch Hand
Joined: Mar 05, 2008
Posts: 2778
2
posted
1
Yes, Jon, your original post made it fairly clear you already know about the ordinal() method. But there is another method that you need, which will help address the problem you asked about, to avoid typing all those names. That's what I was pointing you towards.
Mike Simmons
Ranch Hand
Joined: Mar 05, 2008
Posts: 2778
2
posted
0
Jon Camilleri wrote:
Wouter Oet wrote:Have you looked at the methods of an enum? Which of those could help to iterate through the values?
Mike Simmons wrote:Yes, Jon, your original post made it fairly clear you already know about the ordinal() method. But there is another method that you need, which will help address the problem you asked about, to avoid typing all those names. That's what I was pointing you towards.
The syntax looks more gory, I'm not sure how to translate it to shorter code...
"valueOf
public static <T extends Enum<T>> T valueOf(Class<T> enumType,
String name)
Returns the enum constant of the specified enum type with the specified name. The name must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
Parameters:
enumType - the Class object of the enum type from which to return a constant
name - the name of the constant to return
Returns:
the enum constant of the specified enum type with the specified name
Throws:
IllegalArgumentException - if the specified enum type has no constant with the specified name, or the specified class object does not represent an enum type
NullPointerException - if enumType or name is null
Since:
1.5"
Well, no, that wasn't it either. Keep reading. And is it really necessary to requote all this stuff here? I would think we're all able to follow links.
Mike Simmons
Ranch Hand
Joined: Mar 05, 2008
Posts: 2778
2
posted
0
By the way, if someone could edit the first post in this thread to remove all those the extra useless spaces at the end of line 29 of the code block, it would do wonders for making this thread readable again. It didn't look this bad when first posted, so I don't know what happened. But that's why we're all having to use the horizontal scroll bars now.
Mike Simmons wrote:By the way, if someone could edit the first post in this thread to remove all those the extra useless spaces at the end of line 29 of the code block, it would do wonders for making this thread readable again. It didn't look this bad when first posted, so I don't know what happened. But that's why we're all having to use the horizontal scroll bars now.
Sorry, if there's some spacing I can update let me know I didn't see anything out of place, I was just asking for an example..