Is there any Scala feature that allows you to call a method whose name is stored in a string?

后端 未结 4 1268
刺人心
刺人心 2020-12-05 03:20

Assuming you have a string containing the name of a method, an object that supports that method and some arguments, is there some language feature that allows you to call th

4条回答
  •  有刺的猬
    2020-12-05 03:29

    Yes. It's called reflection. Here's a link to one way, using some experimental stuff However you should remember that Scala is not a dynamic language, and may not be able to easily do some things that scripting languages can do. You're probably better doing a match on the string, and then calling the right method.

提交回复
热议问题