2016-11-04 20 views
0

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

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()); 
相關問題