print the closure definition/source in Groovy

前端 未结 2 425
孤独总比滥情好
孤独总比滥情好 2020-12-03 08:07

Anyone who knows how the print the source of a closure in Groovy?

For example, I have this closure (binded to a)

def a = { it.twice() }          


        
2条回答
  •  无人及你
    2020-12-03 08:44

    That isn't possible in groovy. Even when a groovy script is run directly, without compiling it first, the script is converted into JVM bytecode. Closures aren't treated any differently, they are compiled like regular methods. By the time the code is run, the source code isn't available any more.

提交回复
热议问题