Lambda rewriting heuristics

このページの内容

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問

Following document applies for version 4.0.5 or above

 

Clover applies some heuristic methods in order to reduce compilation errors connected with lambda expression instrumentation which are described with more details in here. During instrumentation Clover looks for invocation of some of java.util.stream.Stream and Guava classes' methods which are called with a lambda expression as an argument. With such conditions Clover rewrites lambda expressions into a block form.

With implemented heuristic, such code:

public static Stream<String> test(List<String> input) {
    return input.stream()
            .map(e -> e.toUpperCase())
            .filter(e -> !e.isEmpty());
}

will be instrumented with the following manner:

public static Stream<String> test(List<String> input) {  
    return input.stream()
            .map(e ->  {return e.toUpperCase();})
            .filter(e -> {return !e.isEmpty();});
}

 

This method has its own limitations, however. It does not apply to method references (refer to this article), so we advice to use lambda expressions instead of method references or lower lambda instrumentation level to from "all" to "all_but_references" (see clover-setup).

The other issue you may encounter is compilation error about unexpected return value (look here). It happens when there's a method with name matching one of the listed below, but taking as an argument a lambda returning void. 

Method list for stream heuristics 

The following methods trigger lambda expression to block form rewriting by Clover:

  • collect
  • compose
  • concat
  • filter
  • flatMap
  • from
  • generate
  • iterate
  • min
  • map
  • max
  • peek
  • reduce
  • transform
  • transformValues
  • thenApply
  • thenCompose

 

最終更新日 2015 年 7 月 10 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.