Sunday, August 31, 2008

Enum - tricky ones...

I was reading something regarding enums yesterday and found two interesting things which I feel I should share with my readers. These are very simple things for those who already know it but may be surprising for those who don't...

- Enums are not expandable at runtime.
So, suppose you have somethings like
enum Car { HONDA, MERC };
then you cannot add another car say FORD as 3rd constant in the list at runtime. You can have as many references you can to point to the enum constants.

- ; is unnecessary at the end of enum definition! :)
Yeh, this is quite funny and surprising, don't know why java developers didn't do it mandatory. Exam may have questions with multiple code sentences in single line, so look out properly where ; is necessary and where it isn't. And now u know that there is no need of ; after } when the enum definition completes.

Thanks!

No comments: