It recently occured to me that the following (sample) enumeration...
enum Color
{
Red,
Green,
Yellow,
Blue
}
... could be r
Yup, the original edition of "Effective Java" by Joshua Bloch, which was released prior to Java 1.5 and native support for enums in Java, demonstrated the Typesafe Enum
pattern. Unfortunately, the latest release of the book targets Java > 1.5, so it uses Java enums instead.
Second, you can't cast from int to enum in Java.
Color nonsenseColor = (Color)17; // compile-error
I can't speak for other languages though.