幕布斯6054654
2023-06-14 14:37:12
我收到以下編譯錯(cuò)誤: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現(xiàn)在我的印象是,您應(yīng)該能夠通過這種方式將所有 Stream 元素放入一個(gè)列表中。我對(duì) Java 有點(diǎn)陌生......我在這里不明白什么?這是在 Util.java 中導(dǎo)致問題的函數(shù):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貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超17個(gè)贊
改成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 ...
}
添加回答
舉報(bào)
0/150
提交
取消