代码之家  ›  专栏  ›  技术社区  ›  Lin Ma

Java哈希映射问题[重复]

  •  1
  • Lin Ma  · 技术社区  · 8 年前

    知道为什么下面的行有相关的错误消息吗?谢谢

    密码

    Map<int,boolean> buffer = new HashMap<int, boolean>();
    

    错误消息

    Description Resource    Path    Location    Type
    Syntax error, insert "Dimensions" to complete ReferenceType
    
    1 回复  |  直到 8 年前
        1
  •  5
  •   Yassin Hajaj    8 年前

    你的代码应该是这样的:

    Map<Integer,Boolean> buffer = new HashMap<Integer, Boolean>();
    

    不能将基元类型与泛型一起使用。

    您需要为它们使用Wrapper类。