Ответ 1
Есть несколько простых способов помочь компилятору.
назначить сопряжение локальной переменной:
public static void main(String[] args) {
Expectations expectations = new Expectations();
Matcher<Integer> instanceOf = Matchers.instanceOf(Integer.class);
expectations.with(instanceOf);
}
вы можете указать параметр типа с типом свидетеля следующим образом:
public static void main(String[] args) {
Expectations expectations = new Expectations();
expectations.with(Matchers.<Integer>instanceOf(Integer.class));
}
оберните экземпляр instanceOf в свой собственный безопасный метод:
public static void main(String[] args) {
Expectations expectations = new Expectations();
expectations.with(instanceOf(Integer.class));
}
public static <T> Matcher<T> instanceOf(Class<T> type) {
return Matchers.instanceOf(type);
}
Я предпочитаю последнее решение, так как оно многократно используется, и тест остается легко читаемым.