Groovy equivalent for Java 8 Lambda Expression -
i have got java interface 1 method.
// java interface public interface auditoraware { auditor getcurrentauditor(); }
i using java 8 lambda look create insance of auditoraware
following.
// java 8 lambda create instance of auditoraware public auditoraware currentauditor() { homecoming () -> auditorcontextholder.getauditor(); }
i trying write above java implementation in groovy.
i see there many ways implement interfaces in groovy shown in groovy ways implement interfaces documentation.
i have implemented above java code groovy equivalent using implement interfaces map shown in above mentioned documentation.
// groovy equivalent "implement interfaces map" method auditoraware currentauditor() { [getcurrentauditor: auditorcontextholder.auditor] auditoraware }
but implement interfaces closure method seems more concise shown in documentation example. however, when seek implement follows, intellij
shows errors saying ambiguous code block.
// groovy equivalent "implement interfaces closure" method ??? auditoraware currentauditor() { {auditorcontextholder.auditor} auditoraware }
how can alter java 8 lambda implementation groovy equivalent using "implement interfaces closure" method?
as commented dylan bijnagte, next code worked.
// groovy equivalent "implement interfaces closure" method auditoraware currentauditor() { { -> auditorcontextholder.auditor} auditoraware }
section paramter notes of documentation on groovy closure explain this.
java groovy lambda closures java-8
No comments:
Post a Comment