how do i override valueOf for an enum?
I'm having troubles figuring out exactly how to override valueOf for an enum. ex:
publicenum foo{
a, b, c
foo(){}
publicstatic ? valueOf(String s){
return ?
}
}
What's the correct class for the ? so that it is overrides the method? Thanks!
[622 byte] By [
galaxyya] at [2007-11-27 6:15:29]

"the return type is foo"
this didn't work when I put it in there:
public static foo valueOf(String s)
Overriding this method makes my enum much more robust. I want to try to first throw the string up to the super.valueOf and then if there is an exception use a different set of rules for returning....i hope that makes sense.
> "the return type is foo"
>
> this didn't work when I put it in there:
That's because you can't override it.
>
> public static foo valueOf(String s)
>
> Overriding this method makes my enum much more
> robust.
No it would't. It would actually make it less robust.
> I want to try to first throw the string up to
> the super.valueOf and then if there is an exception
> use a different set of rules for returning....i hope
> that makes sense.
Nope :)
kajbja at 2007-7-12 17:26:10 >

> That's because you can't override it.
lame!
> No it would't. It would actually make it less robust.
I want to allow the valueOf() to accept a wider range of String thus making it more robust. Now I have to make a whole separate method and a try/catch block for when the normal valueOf() throw an IllegalArgumentException (as it can't match the string to the enum). That's a lot of extra code and is less elegant imo :)