![](/img/trans.png)
[英]Why does the Java Stream API omit the 'toArray(T[] a)' overload for writing to an existing array?
[英]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.