我收到以下编译错误:javac -cp "/Users/myname/Desktop/Projects/Project/target/jarname.jar" Util.java -Xlint:uncheckedUtil.java:51: error: incompatible types: inference variable R has incompatible bounds tags = Arrays.stream(tagArray).collect(Collectors.toList()); ^ equality constraints: List<String> upper bounds: ArrayList<String>,Object where R,A,T are type-variables: R extends Object declared in method <R,A>collect(Collector<? super T,A,R>) A extends Object declared in method <R,A>collect(Collector<? super T,A,R>) T extends Object declared in interface Stream1 error现在我的印象是,您应该能够通过这种方式将所有 Stream 元素放入一个列表中。我对 Java 有点陌生......我在这里不明白什么?这是在 Util.java 中导致问题的函数:public static GoogleMerchantDetailsDto convertGoogleMerchantDetails(SqlRow row) { Array rawTagArray = (Array) row.get("tags"); ArrayList<String> tags = new ArrayList(); if (rawTagArray != null) { String[] tagArray = Util.toStringArray(rawTagArray); tags = Arrays.stream(tagArray).collect(Collectors.toList()); } String distanceFrom = String.format("%,.1f", row.getDouble("distance_from")); String latitude = String.format("%,.6f", row.getDouble("latitude")); String longitude = String.format("%,.6f", row.getDouble("longitude")); GoogleMerchantDetailsDto googleMerchant = GoogleMerchantDetailsDto.builder().withId(row.getString("id")) .withName(row.getString("name")).withTags(tags).withDistanceFrom(distanceFrom).withLatitude(latitude) .withLongitude(longitude).withIsFavorite(row.getBoolean("is_favorite")) .withWaitlist(row.getInteger("waitlist")).withAddress1(row.getString("vicinity")).build(); return googleMerchant;}
1 回答
慕慕森
TA贡献1856条经验 获得超17个赞
改成ArrayList<String>这样List<String>:
public static GoogleMerchantDetailsDto convertGoogleMerchantDetails(SqlRow row) {
Array rawTagArray = (Array) row.get("tags");
List<String> tags = new ArrayList();
if (rawTagArray != null) {
String[] tagArray = Util.toStringArray(rawTagArray);
tags = Arrays.stream(tagArray).collect(Collectors.toList());
}
// ... rest of the method ...
}
添加回答
举报
0/150
提交
取消