以下代码无法在Eclipse Neon 4.6.0上编译:
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
public class Test {
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void main(String[] args) {
Map rawMap = new HashMap();
Map<String, Integer> map = new HashMap<>(rawMap); // Type mismatch: cannot convert from HashMap to Map<String, Integer>
map = Collections.synchronizedMap(rawMap); // No error here
}
}
从命令行调用javac(1.8)时,完全相同的代码编译正常。它也适用于旧版本的Eclipse(Mars 2)。这是什么问题?