JSoup:不存在类型变量的实例,因此String符合Element

时间:2016-11-04 01:41:13

标签: java-8 jsoup

我正在使用JSoup来解析网页。

这是我的代码:

List<Element> nodes = inodes.stream()
                    .filter(n -> n.child(0).text().contains("hello"))
                    .map(n -> n.data())
                    .collect(Collectors.toList());

当我运行它时,我收到此错误:

        equality constraints: Element
    lower bounds: String
  where T is a type-variable:
    T extends Object declared in method <T>toList()

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

Element.data返回类型为String,因此collect返回类型应为List<String>,如:

List<String> nodes = inodes.stream()
                    .filter(n -> n.child(0).text().contains("hello"))
                    .map(n -> n.data())
                    .collect(Collectors.toList());