How to correctly use HashMap?

前端 未结 6 1881
长情又很酷
长情又很酷 2021-01-04 07:28
HashMap savedStuff = new HashMap();
savedStuff.put(\"symbol\", this.symbol); //this is a string
savedStuff.put(\"index\", this.index); //this is an int
6条回答
  •  悲&欢浪女
    2021-01-04 07:57

    Using HashMap is probably the best you can do if you insist on having heterogeneous values in the same map -- you'll need to cast those to do anything useful when you retrieve them (and how are you going to know what type to cast them to...?), but at least you'll be typesafe with respect to the keys.

提交回复
热议问题