Scala 提升类型不匹配?
我目前正在编写一个网络应用程序,我想使用提交表单中的值,但出现类型不匹配:
类型不匹配;发现:connectfour.Board=>选项[Int] 必需:() => 我的代码
看起来像这样:
var value=0
"name=value" #> SHtml.onSubmit(s => asInt(s).foreach(value= _)) &
// when the form is submitted, process the variable
"type=submit" #> SHtml.onSubmitUnit(askForHumanMove)
和我的askForHumanMove 方法:
def askForHumanMove(board: connectfour.Board): Option[Int] = {
Some(value)
}
希望有人可以帮助我解决这种类型不匹配的问题。
谢谢你!
此致, 约翰
I am programming a webapp at the moment and I want to use a value from a submit form but get a type mismatch:
type mismatch; found : connectfour.Board=> Option[Int] required: () => Any
My code looks like this:
var value=0
"name=value" #> SHtml.onSubmit(s => asInt(s).foreach(value= _)) &
// when the form is submitted, process the variable
"type=submit" #> SHtml.onSubmitUnit(askForHumanMove)
and my askForHumanMove method:
def askForHumanMove(board: connectfour.Board): Option[Int] = {
Some(value)
}
Hope somebody can help me with this type mismatch.
Thank you!
Best regards,
John
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

在我看来,
onSubmitUnit
接受() =>; Any
作为参数。但是您传递的方法被提升到函数Board =>;选项[Int]
。这些类型不兼容。在调用
onSubmitUnit
方法时,您的范围内是否有相关的Board
实例?如果是这样,修复方法很简单:It looks to me that
onSubmitUnit
accepts a() => Any
as a parameter. But you are passing a method which is being lifted into a functionBoard => Option[Int]
. These types are not compatible.Do you have the relevant instance of
Board
in scope at the point of calling theonSubmitUnit
method? If so, the fix is simple: