我使用的是javax.Json.JsonArray
對象。JsonArray.getvaluesAs不帶String.class作爲參數
方法:返回JsonArray
作爲列表。所以我想要做的是將List
變成Set
。這是我做的:
Set values= new HashSet(myjsonArray.getValuesAs(null));
這工作得很好,但我知道,myjsonArray
只包含String
。所以我真正想要做的是:
Set<String> values= new HashSet(myjsonArray.getValuesAs(String.class));
出於某種原因,上面的代碼我收到編譯器錯誤:
The generic method getValuesAs(Class<T>) of type JsonArray is not applicable for the arguments (Class<String>). The inferred type String is not a valid substitute for the bounded parameter <T extends JsonValue>
我可以讓我的Set<String>
使用循環建立,但我儘量避免,那麼是否有一個簡單的解決上述錯誤?
@aegean嗯試過了,它得到了同樣的錯誤。 – nafas 2014-09-23 09:10:21
如果有人讀過這樣的話:不要使用javax.Json.JsonArray類,它會讓我哭泣... – nafas 2014-09-23 10:25:03