我使用的是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