OnJava8-Examples/enums/UpcastEnum.java

20 lines
438 B
Java
Raw Normal View History

2015-09-07 11:44:36 -06:00
// enums/UpcastEnum.java
2015-06-15 17:47:35 -07:00
// <20>2015 MindView LLC: see Copyright.txt
// No values() method if you upcast an enum
enum Search { HITHER, YON }
public class UpcastEnum {
public static void main(String[] args) {
Search[] vals = Search.values();
Enum e = Search.HITHER; // Upcast
// e.values(); // No values() in Enum
for(Enum en : e.getClass().getEnumConstants())
System.out.println(en);
}
2015-09-07 11:44:36 -06:00
}
/* Output:
2015-06-15 17:47:35 -07:00
HITHER
YON
2015-09-07 11:44:36 -06:00
*/