Table of Contents
With the introduction of Java 1.5, Kenya has now added some of the new Java 1.5 features, namely generics, enumerated types and autoboxing.
An enumerated type is a special class type that can only take one of a limited number of values and ( in Kenya ) does not have any member variables.
They syntax for declaring an enumerated type is:
enum TYPE_NAME { child1, child2, child3; }
With an enumerated type defined, you can then create variables which have the value of one of the children ( or null ):
void main() { Cows c = Cows.Daisy; println(c); } enum Cows { Daisy, Maizy, Haizy; }
One of the most useful things you can do with an enumerated type is use it for a switch variable. In switch cases, you must remember not to put the type-name as a prefix for the children.
Example 4.1. Enumerated Types and Switch Example
void main() { Dogs d = Dogs.Scoobie; printDetails( d ); } void printDetails( Dogs d ){ switch ( d ){ case Lassie:{ println( d + " come home!"); break; } case Scoobie:{ println( d + "-dooby-do!" ); break; } case Timmy:{ println( d ); break; } } } enum Dogs{ Lassie, Scoobie, Timmy; }