I have this Java interface with only one method.
I used the Java 8 Lambda expression to create an AuditorAware feel like this.
// Java 8 Lambda to create instance of AuditorAware public AuditorAware currentAuditor() { return () -> AuditorContextHolder.getAuditor(); }
I am trying to write the above Java implementation in Groovy.
I see that there are many ways to implement interfaces in groovy, as shown in this Groovy interface implementation methods .
I implemented the above Java code up to the groovy equivalent using the implementation interfaces with the map, as shown in the above documentation.
// Groovy Equivalent by "implement interfaces with a map" method AuditorAware currentAuditor() { [getCurrentAuditor: AuditorContextHolder.auditor] as AuditorAware }
But the implementation of interfaces with the closure method looks more concise, as shown in the sample documentation. However, when I try to implement it as follows, IntelliJ shows errors saying Undefined code .
// Groovy Equivalent by "implement interfaces with a closure" method ??? AuditorAware currentAuditor() { {AuditorContextHolder.auditor} as AuditorAware }
How can I change the Java 8 lambda implementation to the groovy equivalent using the "implement interfaces with closure" method?
source share