I found a workaround I can live with, by specifying the lambda as constructor argument:
open class Transformer<in A, out B>(val lambda: (A) -> B) {
fun invoke(a: A): B = lambda(a)
}
object AgeTransformer : Transformer<ZonedDateTime, Int>({ z ->
ChronoUnit.YEARS.between(z, ZonedDateTime.now()).toInt()
})
This works for me, as I use reflection, and can still call the invoke function as usual.
Nevertheless, I still think “SAM objects” with a fun object ... syntax would be a useful thing.