HashMap and int as key

前端 未结 11 2055
说谎
说谎 2020-11-28 23:32

I am trying to build a HashMap which will have integer as keys and objects as values.

My syntax is:

HashMap myMap = new HashMap&         


        
11条回答
  •  生来不讨喜
    2020-11-28 23:55

    I don't understand why I should add a dimension (ie: making the int into an array) since I only need to store a digit as key.

    An array is also an Object, so HashMap is a valid construct that uses int arrays as keys.

    Compiler doesn't know what you want or what you need, it just sees a language construct that is almost correct, and warns what's missing for it to be fully correct.

提交回复
热议问题