scala: How to pass an expanded list as varargs into a method?

前端 未结 2 1231
梦谈多话
梦谈多话 2020-12-25 10:07

When creating a Map in scala, I call Map(entities.map{e => e.id -> e}), and I get:

found   : scala.collection.mutable.Indexed         


        
相关标签:
2条回答
  • 2020-12-25 10:14

    Try this: Map(entities.map{e => e.id -> e}:_*)

    Explicitly typing it as a varargs using :_* seems to work.

    0 讨论(0)
  • 2020-12-25 10:27

    Or this should work too:

    entities.map{e => e.id -> e} toMap
    
    0 讨论(0)
提交回复
热议问题