为了账号安全,请及时绑定邮箱和手机立即绑定

错误:类型不兼容:推理变量 R 具有不兼容的边界

错误:类型不兼容:推理变量 R 具有不兼容的边界

幕布斯6054654 2023-06-14 14:37:12
我收到以下编译错误: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 ...

}


查看完整回答
反对 回复 2023-06-14
  • 1 回答
  • 0 关注
  • 168 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信