读书人

6.34 运用接口模仿枚举类继承

发布时间: 2013-08-13 16:43:28 作者: rapoo

6.34 使用接口模仿枚举类继承

枚举类不能继承其它类,但是枚举类可以继承接口,如下接口:

private static <T extends Enum<T> & Operation> void test(Class<T> opSet,double x, double y) {for (Operation op : opSet.getEnumConstants())System.out.printf("%f %s %f = %f%n", x, op, y, op.apply(x, y));}private static void test(Collection<? extends Operation> opSet, double x,double y) {for (Operation op : opSet)System.out.printf("%f %s %f = %f%n", x, op, y, op.apply(x, y));}

?

?

?

?

读书人网 >编程

热点推荐