java.lang.IllegalStateException:流已被操作或关闭,对于多个过滤器语句

在执行java.lang.IllegalStateException: stream has already been operated upon or closed时获取findFirst()。有人知道为什么吗?

public ResultCode getcodeBySourceTypeScope(final List<CodeResult> results,final String source,final String type,final String scope) {
    if (results.isEmpty()){
        return null;
    }
    final Stream<ResultCode> resultStream = results
            .get(0)
            .getcodes()
            .stream();

    if(source != null){
        resultStream.filter(code -> code.getsource().equals(source));
    }

    if(type != null){
        resultStream.filter(code -> code.getType().equals(type));
    }

    if(scope != null){
        resultStream.filter(code -> String.valueOf(code.getScope()).equals(scope));
    }

    return resultStream
            .findFirst()
            .orElse(null);
}
hailong161 回答:java.lang.IllegalStateException:流已被操作或关闭,对于多个过滤器语句

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3168373.html

大家都在问