user9068137
user9068137

Reputation:

Why doesn't stream() work in Scala the way it does in Java? Is there any other API that does the same as stream() API?

Trying to run the below code in Scala. It returns a "missing parameter type" error.

def printTree(e: Element, depth: Int){
    System.out.println("Number of children in element : ",e.getChildren().getClass());
    System.out.println(StringUtils.repeat("\t", depth) + e.getText());
    e.getChildren().stream().filter(c=>c instanceOf Element).foreach(c=>printTree((Element)c, depth+1));
}

Upvotes: 0

Views: 160

Answers (1)

Andronicus
Andronicus

Reputation: 26046

In Scala you don't need to explicitly work with Java streams. If e.getCgildren() return an Array, you can omit .stream() and the rest will compile.

Upvotes: 1

Related Questions