合法代码不能在滚烫中编译

e5nszbig  于 2021-06-04  发布在  Hadoop
关注(0)|答案(1)|浏览(417)

我正在写一个mapreduce工作在烫伤和有困难编译代码,看起来完全合法的我。

val persistenceBins = List[Int](1000 * 60 * 60, 2 * 1000 * 60 * 60, 4 * 1000 * 60 * 60)
val persistenceValues = persistenceBins.map(bin: Int => (bin, getPersistenceValues(connections, bin)) )

连接件为richpipe。getpersistencevalues与上述代码在同一类中定义,如下所示:

def getPersistenceValues(connections: RichPipe, binSize: Int): RichPipe = { ... }

我经常会犯这样的错误:

Error:(45, 87) ')' expected but '(' found.
val persistenceValues = persistenceBins.map(bin: Int => (bin, getPersistenceValues(connections, bin)) )
                                                                                  ^
Error:(45, 107) ';' expected but ')' found.
val persistenceValues = persistenceBins.map(bin: Int => (bin, getPersistenceValues(connections, bin)) )
                                                                                                      ^

我搞不懂发生了什么事。这些错误在我看来毫无意义。我做错什么了?

xcitsw88

xcitsw881#

你不能跳过括号。这段代码应该可以帮助您理解错误所在。

scala> val persistenceBins = List[Int](1000 * 60 * 60, 2 * 1000 * 60 * 60, 4 * 1000 * 60 * 60)
persistenceBins: List[Int] = List(3600000, 7200000, 14400000)

scala> val persistenceValues = persistenceBins.map((bin: Int) => (bin, 0))
persistenceValues: List[(Int, Int)] = List((3600000,0), (7200000,0), (14400000,0))

相关问题