Groovy actually has no reference to the instance method with instance diversity (EDIT: Bye. See Wavyx's comment on this answer.), So you should fake it with closures instead. When using the reference syntax of the instance method in Java 8, you really set up the equivalent lambda, which expects the calling instance to be the first (in this case, only) argument.
So in order to get the same effect in Groovy, we need to create a closure that uses the default argument it
as the calling instance. Like this:
PersonBulkInserter() { super("sample", "unit_test") mapString("first_name", { it.firstName } as Function) mapString("last_name", { it.lastName } as Function) mapDate("birth_date", { it.birthDate } as Function) }
Note the use of Groovy property notation here, and that you must use the Closure
type for @FunctionalInterface
expected by the mapString()
or mapDate()
method.
source share