call name of method contained in a string

前端 未结 1 1458
情书的邮戳
情书的邮戳 2020-12-18 17:46

How can I call a method based on the value of a string in Groovy? For example instead of

switch (val) {
case \"one\":
    Obj.one()
    break
case \"two\":
          


        
相关标签:
1条回答
  • 2020-12-18 18:02

    Dynamic method invocation looks like this

    obj."$val"()
    
    0 讨论(0)
提交回复
热议问题