Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么';t stream()在Scala中的工作方式与在Java中的工作方式相同吗?是否有其他API与stream()API相同?_Java_Scala_Java 8_Functional Programming_Java Stream - Fatal编程技术网

为什么';t stream()在Scala中的工作方式与在Java中的工作方式相同吗?是否有其他API与stream()API相同?

为什么';t stream()在Scala中的工作方式与在Java中的工作方式相同吗?是否有其他API与stream()API相同?,java,scala,java-8,functional-programming,java-stream,Java,Scala,Java 8,Functional Programming,Java Stream,正在尝试在Scala中运行以下代码。它返回“缺少参数类型”错误 在Scala中,您不需要显式地使用Java流。如果e.getCgildren()返回一个数组,则可以省略.stream(),其余部分将编译 什么是元素(完全限定名?),这与spark有什么关系?通常,.stream()会将scala集合转换为流,一种特殊的惰性数据结构元素的c实例和(元素)c不是有效的scala。@AlexeyRomanov Yes,我把它改成了c.instanceOf[Type],但它不起作用。c.isInstan

正在尝试在Scala中运行以下代码。它返回“缺少参数类型”错误


在Scala中,您不需要显式地使用Java流。如果
e.getCgildren()
返回一个
数组
,则可以省略
.stream()
,其余部分将编译

什么是
元素
(完全限定名?),这与spark有什么关系?通常,
.stream()
会将scala集合转换为
,一种特殊的惰性数据结构
元素
的c实例和
(元素)c
不是有效的scala。@AlexeyRomanov Yes,我把它改成了
c.instanceOf[Type]
,但它不起作用。
c.isInstanceOf[Element]
c.asInstanceOf[Element]
。感谢您的回复@Andronicus
e.getChildren()
是一个类org.jdom.ContentList$FilterList类类型,而不是使用以下方法解决此问题的数组:
e.getChildren().filter(c=>c.isInstanceOf[Element]).foreach(c=>printTree(c.asInstanceOf[Element],depth+1))
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));
}