有人可以解释一下为什么以下内容不起作用吗:
long la[] = new long[] {1,2,3};
Arrays.stream(la).map(Long::valueOf).collect(Collectors.toSet());
当这样做时:
String la[] = new String[] {"1","2","3"};
Arrays.stream(la).map(Long::valueOf).collect(Collectors.toSet());
前者会产生编译错误,而后者不会。编译错误(在Eclipse中)非常晦涩难懂,我无法理解。
Arrays.stream(la).boxed().collect(Collectors.toSet());
- tobias_klong -> long
函数时的long -> Long
函数并不是问题(你只需要进行不必要的转换)。问题出在collect
调用上。 - Alexis C.