我想用方法引用來壓縮我的代碼。下面是我試圖改善線:方法引用和鏈式謂詞
assertThat("only true & false strings allowed",
records.stream().map(Record::getType)
.allMatch(s -> "true".equals(s) || "false".equals(s)));
有了方法引用它可能是更漂亮:
assertThat("only true & false strings allowed",
records.stream().map(Record::getType).allMatch("true"::equals));
但我無論如何加上「假」的謂詞?
有一個[討論](http://mail.openjdk.java.net/pipermail/core- libs-dev/2015-May/033137.html)在core-libs-dev上添加「Predicate.of」。如果發生這種情況,我們可以編寫'.allMatch(Predicate.of(「true」:: equals)。或(「false」:: equals))' – Misha