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