0

when pressing ctrl+space in eclipse I remember it used to match the objects for the data type in the diamond operator. but it dosn't anymore . for example :

public static void main(String[] args) {
HashMap<String, String> map = new HashMap<**MISSING**>() }

anyway to turn it back on? thnx.

4

2 回答 2

1

可能是因为您使用的是 Java7 编译器,它不需要菱形运算符中的参数。

在此处阅读更多信息:http ://docs.oracle.com/javase/7/docs/technotes/guides/language/type-in​​ference-generic-instance-creation.html

于 2013-11-05T09:39:18.417 回答
1

你在运行 Java 7 吗?

这是他们添加的一项新功能,称为“用于创建通用实例的类型推断

只要编译器可以从上下文推断类型参数,您就可以用一组空类型参数 (<>) 替换调用泛型类的构造函数所需的类型参数。这对尖括号被非正式地称为菱形。

在 Java 7 之前:

Map<String, List<String>> myMap = new HashMap<String, List<String>>();

现在你可以这样做:

Map<String, List<String>> myMap = new HashMap<>();
于 2013-11-05T09:39:56.257 回答