Before
Java 8 you would create this anonymous class to do exactly the same
And to fix your compiler error, you need something like
So the method signature of your static
containsTwo method is actually
containsTwo(List<Integer> list, Integer num) (if you try to switch these parameter types, you'll get a compiler error).