Just ran into this post trying to fix it for myself. Gave me just enough information to work it out.
You can give the compiler just enough to persuade it to compile by casting the return value from hasItems to a (raw) Matcher, eg:
ArrayList<Integer> actual = new ArrayList<Integer>();
ArrayList<Integer> expected = new ArrayList<Integer>();
actual.add(1);
expected.add(2);
assertThat(actual, (Matcher) hasItems(expected));
Just in case anybody else is still suffering ...
Edit to add:
In spite of the up votes, this answer is wrong, as Arend points out below. The correct answer is to turn the expected into an array of Integers, as hamcrest is expecting:
ArrayList<Integer> actual = new ArrayList<Integer>();
ArrayList<Integer> expected = new ArrayList<Integer>();
actual.add(1);
expected.add(2);
assertThat(actual, hasItems(expected.toArray(new Integer[expected.size()])));
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…