可以用方法参考替换

时间:2017-12-15 11:35:53

标签: android lambda

我有这样的代码,但编译器提出了用方法引用替换accounts != null部分的建议。我该怎么做? 也许有其他可能性来检查

mMainApi.accounts(user, password)
            .filter(accounts -> accounts != null)
            .map(/* Something here */)
            .subscribe();

我找到了一个使用.filter(Objects::nonNull)的解决方案,但此解决方案需要Android API> 24,所以这实际上没有用。

1 个答案:

答案 0 :(得分:0)

你可以尝试下面的代码

mMainApi.accounts(user, password)
            .filter(accounts ->{ 
              return accounts!=null;
            })
            .map(/* Something here */)
            .subscribe();
相关问题