Why doesn't the diamond operator work within a addAll() call in Java 7?
问题 Given this example from the generics tutorial. List<String> list = new ArrayList<>(); list.add("A"); // The following statement should fail since addAll expects // Collection<? extends String> list.addAll(new ArrayList<>()); Why does the last line not compile, when it seems it should compile. The first line uses a very similar construct and compiles without a problem. Please explain elaborately. 回答1: First of all: unless you're using Java 7 all of this will not work, because the diamond <>