UserData.retrieve
类型为(m: Map[String, String]) => User
的地方
并且UserData.update
的类型为(r: spark.sql.Row) => Unit
为什么
receipts map UserData.retrieve
工作正常,但是当我跑步
events foreach UserData.update
它导致以下错误:
missing argument list for method update in object UserData
Unapplied methods are only converted to functions when a function type is expected.
You can make this conversion explicit by writing `update _` or `update(_)` instead of `update`.
我在文档中看到map
期望func: (T) ⇒ U
和foreach
期望f: (T) ⇒ Unit
,所以在我看来,编译器应该将{{ 1}}和map
,但仅对foreach
这样做。为什么?
n.b。我知道我可以通过显式转换来使此map
通话成功
foreach
但是在这里我要寻求帮助,以了解我为什么要这么做。
答案 0 :(得分:1)
只有在需要函数类型时,才会将未应用的方法转换为函数。
数据集上的foreach重载,可以用ForeachFunction [T]或T => Unit调用。
编译器没有足够的信息来解决正在调用哪个重载方法,因此将不应用该函数。