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
Scala未指定类型_Scala - Fatal编程技术网

Scala未指定类型

Scala未指定类型,scala,Scala,我有下面的spark代码片段 但会出现以下错误: :8:错误:缺少参数类型 发生在这里: val index:Int= col1(i) ; tokened +=splitted(index) + " " ; } } ^ 我无法确定它从何处开始,因为似乎我已经指定了所有属性。我还需要返回字符串,所以方法是string=>string(目前是string->unit),这是我第一次在scala中编码,如果这是一个愚蠢的问题,我深表歉意 l

我有下面的spark代码片段

但会出现以下错误:

:8:错误:缺少参数类型

发生在这里:

       val index:Int= col1(i) ; tokened +=splitted(index) + " " ;  } } 
                     ^
我无法确定它从何处开始,因为似乎我已经指定了所有属性。我还需要返回字符串,所以方法是string=>string(目前是string->unit),这是我第一次在scala中编码,如果这是一个愚蠢的问题,我深表歉意

line => { var col1:Array[Int] = Array(1,2) ; var tokened:String = "" ; 
    var splitted:Array[String]=line.split(" ") ;  
    for (i<- 0 to col1.length) { 
        val index:Int= col1(i); 
        tokened +=splitted(index) + " " ;  
    } 
} 
line=>{var col1:Array[Int]=Array(1,2);标记的var:String=”“;
var splitted:Array[String]=line.split(“”);

对于(i我想这就是你需要的:

(line: String) => { /* Previously missing type annotation */
  var col1:Array[Int] = Array(1,2)
  var tokened:String = ""
  var splitted:Array[String]=line.split(" ")

  for (i<- 0 to col1.length) { 
    val index:Int= col1(i)
    tokened += splitted(index) + " "
  }

  tokened /* Return value */
}

我想这就是你需要的:

(line: String) => { /* Previously missing type annotation */
  var col1:Array[Int] = Array(1,2)
  var tokened:String = ""
  var splitted:Array[String]=line.split(" ")

  for (i<- 0 to col1.length) { 
    val index:Int= col1(i)
    tokened += splitted(index) + " "
  }

  tokened /* Return value */
}

给定的行号相当无用。请在标记错误发生位置的代码中添加注释。给定的行号相当无用。请在标记错误发生位置的代码中添加注释。