Different types in Map Scala

后端 未结 7 1720
情书的邮戳
情书的邮戳 2020-12-14 03:11

I need a Map where I put different types of values (Double, String, Int,...) in it, key can be String.

Is there a way to do this, so that I get the correct type with

7条回答
  •  情书的邮戳
    2020-12-14 03:38

    (a) Scala containers don't track type information for what's placed inside them, and

    (b) the return "type" for an apply/get method with a simple String parameter/key is going to be static for a given instance of the object the method is to be applied to.

    This feels very much like a design decision that needs to be rethought.

提交回复
热议问题