class Test { static class TKey { } public interface Getter { T getValue(TKey key); } static final TKey KEY_B = new TKey<>(); public static void f(Getter getter) { String name = getter.getValue(KEY_B) ? "foo" : "bar"; } }