在Eclipse中使用此代码时:
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class Test {
public static void main(String[] args) {
List<Object> objs = Arrays.asList(new Object(), new Object());
Set<String> s = objs.stream().collect(HashSet::new, HashSet::add, Object::toString);
System.out.println(s);
}
}
我明白了:
Internal compiler error: java.lang.ArrayIndexOutOfBoundsException: 0 at
org.eclipse.jdt.internal.compiler.lookup.ConstraintExpressionFormula.reduceReferenceExpressionCompatibility(ConstraintExpressionFormula
.java:273)
我知道这就是产生错误的这一行:
Set<String> s = objs.stream().collect(HashSet::new, HashSet::add, Object::toString);
不确定它是否相关但我使用:
插件:支持Java 8的Eclipse Java开发工具修补程序(适用于Kepler SR2)和支持Java 8的Eclipse插件开发环境修补程序(适用于Kepler SR2)
java.runtime.version = 1.8.0-B132
这是截图:
我知道收集方法不正确,但为什么我没有编译器错误告诉类似:
- The method collect(Supplier<R>, BiConsumer<R,? super Object>, BiConsumer<R,R>) in the type Stream<Object> is not applicable for the arguments etc.