Hi, I want to ask about the commits "replace lambda with method referenceā. Some are definitely the way to go, like this:
List<NormalXReference> normalXReferences = getXRefEntries().stream() // - .filter(e -> e instanceof NormalXReference) // + .filter(NormalXReference.class::isInstance) // .map(NormalXReference.class::cast) // .sorted() // .collect(Collectors.toList()); But what is the benefit of this? return tokens.stream() // - .filter(t -> t instanceof COSString) // - .map(t -> ((COSString) t).getString().trim()) // + .filter(COSString.class::isInstance) // + .map(COSString.class::cast) // + .map(COSString::getString) // + .map(String::trim) // .collect(Collectors.toList()); IMHO the new code is both longer and harder to read and will probably perform worse than the lambda version because now three stream operations have to be made instead of a single one. I know my IDE will also suggest this as a refactoring, but I see no gain in it (apart from maybe getting rid of a warning because of the cast, depending on how smart the static analysis is to determine all elements that pass the filter operation are in fact COSString instances. I think the overhead of creating the lambda is probably smaller than that of the additional stream operations. If you are interested, I could maybe do a small jmh benchmark of this on the weekend to be sure. Cheers, Axel (who is currently too busy with other projects to contribute regularly :-/ )