简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM