为什么我不能在函数定义参数中添加“ Val”。出现错误“:”,但弹出“}”

时间:2018-11-09 13:36:24

标签: scala apache-spark spark-submit

我正在尝试使用spark Submit提交此代码。我发现了以下错误。我还想知道如何在Scala中进行函数调用以及如何启动函数定义。我正在调用file_reading fucntion,而我出现以下错误。这是我的函数定义

def file_reading(file: String,val start:Int,val end:Int): Unit = {

这是我遇到的错误:

/home/ram/sbt_project/src/main/scala/Scala_sample.scala:19:33: identifier expected but 'val' found.
[error]   def file_reading(file: String,val start:Int,val end:Int): Unit = {
[error]                                 ^
[error] /home/ram/sbt_project/src/main/scala/Scala_sample.scala:28:1: ':' expected but '}' found.
[error] }
[error] ^
[error] two errors found

1 个答案:

答案 0 :(得分:1)

请在方法中删除val。

of(1, 2, 3, 4).pipe(
  // Throw error when value is 3
  tap(value => { if(value === 3) throw new Error('Oops!') }),
  catchError(err => {
    console.log('Catch error in operator', err);

    // You can rethrow the same error or a new error
    // return throwError(err);

    // Or you can handle the error and return a new observable
    return of(3)
  })
).subscribe(
  value => console.log(value),
  // If `catchError` returns a new observable, then the error 
  // function here will not be called
  err => console.log('Catch error within subscribe', err),
  () => console.log('Done!')
)

请更正循环,接下来您将在这里遇到错误。

路径?

 def file_reading(file: String,start:Int,end:Int): Unit = {