void (Foo foo, String fieldName) { switch (fieldName) { //should not produce error "Constant expression required" > Foo.Fields.bar case Foo.Fields.bar: System.out.printf("Field %s contains: %s", fieldName, foo.getBar()); break; //should not produce error "Constant expression required" > Foo.Fields.foo case Foo.Fields.foo: System.out.printf("Field %s contains: %s", fieldName, foo.getFoo()); break; default: System.out.printf("Foo class doesn't have field: %s", fieldName); } }