• Post Reply Bookmark Topic Watch Topic
  • New Topic

Overriding toString() in enum types  RSS feed

 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was reading an article somwhere that there was a hidden gotcha when overriding the toString method when using enum types and that another method should be overriden in complement to overriding toString() but I can't remember what is was. Anyone have any idea?

Garrett
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I vaguely recall reading something about also overriding valueOf (I think it was a book), but it is false and horribly contrived (valueOf is static) - don't believe everything that you read.
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's exatcly what it was. But you're right overriding toString() has no effect on the valueOf() static method.

don't believe everything that you read.


Good advice.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!