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



我正在使用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()

如何解决这个问题?

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());

相关内容

最新更新