-5

以下代码

public List<Map<String,String>> getPhoneData() {
    List<Map<String, String>> mapp = new List<Map<String, String>>();
    Map<String, Integer> temp
         = new Map<String, Integer>{'type' => 'Profile Value', 'count' => 1};
    return mapp;
}

在给我

Compile Error: Invalid value type: String for Integer

在第 3 行

我想Map用一种价值String和另一种价值来创造Integer。怎么做?

4

1 回答 1

2

删除数字周围的引号,如下所示:

Map<String, Integer> temp = new Map<String, Integer>{'type' => 123, 'count' => 1};

编辑: 当你完全改变你的问题时,实现这一目标的最佳方法是:

public List<Map<String,String>> getPhoneData() {
    List<Map<String, String>> mapp = new List<Map<String, String>>();
    Map<String, String> temp = new Map<String, String>{'type' => 'Profile Value', 'count' => '1'};
    return mapp;
}
于 2012-09-06T13:39:53.890 回答