我在util.TreeSet类中发现其中一个构造函数正在使用new TreeMap泛型类型调用另一个构造函数.
public TreeSet(Comparator<? super E> comparator) {
this(new TreeMap<>(comparator));
}
Run Code Online (Sandbox Code Playgroud)
什么new TreeMap<>意思?那相当于new TreeMap<?>?
Rom*_*ain 17
这是Java 7语法.diamond(<>)是一个简短的方法,要求Java编译器用本地上下文中有意义的东西填充泛型参数(在这种情况下,它将是? super E).