G* Advent Calendar 2017 の6日目は groovy.lang.Closure のインスタンスを Kotlin で生成・取得する方法です。 Groovy! 3分くらいで読み終われます。 groovy.lang.Closure のインスタンスを Kotlin で生成・取得する方法です。Kotlin コードの中で Closure を作って Groovy に渡すということを指しています。 生成方法 早速ですが生成方法です。 あるAというクラスがあって、 Closure の中で用いるプロパティをAから取得したい場合は次のような関数を書きます。 fun <A> closure(a: A, cl: A.() ->Unit): Closure<Unit> = object: Closure<Unit>(a) { fun doCall() = this@closure.cl
![Kotlin で Groovy の Closure のインスタンスを取得・生成する方法 - mike-neckのブログ](https://cdn-ak-scissors.b.st-hatena.com/image/square/a9f27ed2c21d114064b9c19944eca14115b738d4/height=288;version=1;width=512/https%3A%2F%2Fcdn-ak.f.st-hatena.com%2Fimages%2Ffotolife%2Fm%2Fmike_neck%2F20150917%2F20150917235151.png)