dopatraman
dopatraman

Reputation: 13908

JSoup: no instances of type variables exist so that String conforms to Element

I'm using JSoup to parse a webpage.

This is my code:

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

When I run it I get this error:

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

How do I solve this?

Upvotes: 0

Views: 1194

Answers (1)

chengpohi
chengpohi

Reputation: 14227

Element.data return type is String, so collect return type should be List<String>, like:

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

Upvotes: 1

Related Questions