2012-09-06 17 views
-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线

我想用一个数值StringInteger创建Map。怎么做?

+0

错误解释什么是错误的,你的Map是,并且你传递它{String => String}。改为传递{String => Integer}。 –

+0

@EricLeschinski:“type”是'String'。现在检查我的问题 –

+2

别人回答后不要改变问题的性质。 –

回答

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; 
} 
+0

类型是一个字符串 –

+2

你刚刚完全改变了你的问题? ... – Silox

+0

我并没有改变'type'的值来显示它实际上是一个字符串 –

相关问题