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

我收到以下编译错误:


javac -cp "/Users/myname/Desktop/Projects/Project/target/jarname.jar" Util.java -Xlint:unchecked


Util.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 Stream

1 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;

}


幕布斯6054654
浏览 180回答 1
1回答

慕慕森

改成ArrayList<String>这样List<String>:public static GoogleMerchantDetailsDto convertGoogleMerchantDetails(SqlRow row) {&nbsp; &nbsp; Array rawTagArray = (Array) row.get("tags");&nbsp; &nbsp; List<String> tags = new ArrayList();&nbsp; &nbsp; if (rawTagArray != null) {&nbsp; &nbsp; &nbsp; &nbsp; String[] tagArray = Util.toStringArray(rawTagArray);&nbsp; &nbsp; &nbsp; &nbsp; tags = Arrays.stream(tagArray).collect(Collectors.toList());&nbsp; &nbsp; }&nbsp; &nbsp; // ... rest of the method ...}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java