Java - example of specifying multiple constraints in Generic

less than 1 minute read

1
2
3
4
5
6
7
8
9
10
public interface Operation {
}
public class enum TestEnum implements Operation {
}
public class Test {
    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));
    }
}