mercredi 13 décembre 2017

Instantiate a function from a string?

I have a function defined in a string, and need a way to instantiate it :

val myFunction = """fun (file:Int, rank:Int, playerHasWhite: Boolean): Boolean {
    val a = file + 3
    val b = rank - 2
    if (playerHasWhite) a>b else a<b
}
"""

So, is there a simple way, by reflection, to instantiate myFunction ? (I've noticed I may need the jar kotlin-reflect)





Aucun commentaire:

Enregistrer un commentaire