• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

No built-in pred() and succ() for enumerated types?

 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No real question here, just something I thought I'd share and maybe get some comments on.

I was trying to find a way to determine the predecessor and successor of an enumerated type value. Pascal has the Succ() and Pred() functions for ordinal types. However, I couldn't find anything in the standard Enum class and Apache Commons Lang EnumUtils doesn't have anything like that either. Seems like a fairly useful pair of methods to have so I was just wondering why java.lang.Enum doesn't provide pred() and succ()... Did I miss something?

I ended up implementing these myself, along with first() and last(). It was actually pretty short and sweet.

 
reply
    Bookmark Topic Watch Topic
  • New Topic