小编mhl*_*hlz的帖子

如何抑制未经检查的投射警告?

拥有以下代码:

fun doSomething(): List<String> {

    val test: List<*> = arrayListOf("test1", "test2")

    return test as List<String>
}
Run Code Online (Sandbox Code Playgroud)

有没有办法抑制最后一行出现的未经检查的投射警告?我试图@SuppressWarnings("unchecked")在方法级别使用标准的Java 方法,但它没有用.

kotlin

25
推荐指数
1
解决办法
8205
查看次数

Java 8编译器bug与Stream和reduce

我正在编写一个小程序来生成一些随机数,并想获得有关它们的统计信息.我有一个List<AtomicInteger>我想用来输出一些信息.

我尝试使用以下代码将列表减少到总数(例如,所有AtomicIntegers的值的总和):

// not my real initialization code, just for illustration purposes
List<AtomicInteger> values = new ArrayList<>();
for(int i = 0; i < 10; i++) {
    values.add(new AtomicInteger());
}

// this is the problematic reduce
int total = values
    .parallelStream()
    .reduce(0, 
        (currentValue, currentAtomic) 
            -> currentValue + currentAtomic.get(),
        (combiner1, combiner2) -> combiner1 + combiner2);
Run Code Online (Sandbox Code Playgroud)

我的IDE(IntelliJ)根本没有问题,但是对于我当前的javac版本(1.8.0_31),这一行在编译器中导致NullPointerException:

An exception has occurred in the compiler (1.8.0_31). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport)  after checking the Bug …
Run Code Online (Sandbox Code Playgroud)

java java-8

6
推荐指数
1
解决办法
900
查看次数

标签 统计

java ×1

java-8 ×1

kotlin ×1