簡體   English   中英

為什么 stream() 在 Scala 中不像在 Java 中那樣工作? 是否有其他與 stream() API 相同的 API?

[英]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?

嘗試在 Scala 中運行以下代碼。 它返回“缺少參數類型”錯誤。

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

在 Scala 中,您不需要顯式地使用 Java 流。 如果e.getCgildren()返回一個Array ,您可以省略.stream() ,其余部分將被編譯。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM