以下代码段不起作用:FileSystems.getDefault.getPath 来自 java.nio 包
更新:
方法创建计算为:
注意:MyLocation 是一个扩展 MyMessage 的案例类
def creatCalculation(myPlace: MyLocation): MyMessage = {
if (some test) {
//--- some code
} else
MyError("My Calculation already done")
MyAck //returning the case object MyAck which is of type MyMessage
}
//Req 是来自: net.liftweb.http.Req 的类
val someVal: PartialFunction[Req, () => Box[LiftResponse]] {
case "create" :: Nil JsonPostAndApproval s =>
postResponse(s, (j: JValue, p: Permissions, r: Req) => {
createCalculation(fromJValue[MyLocation](j) = {
case "MyAck" => {
val myCalculator: Calculator = new Calculator(FileSystems.getDefault.getPath(fromJsonVal[MyLocation](s._1).path))
val resultsMap = myCalculator.foreach( (p) => Map[String, Int])
for( (myKey, myValue) <- resultsMap) {
printf("key: %s, value: %sn", myKey, myValue)
}
}
})
} ) ("Failed to calculate")
}
编译器像这样抱怨:
[error] C:UsersluluExampleHandler.scala:129: missing arguments for
method fromJValue in package json;
[error] follow this method with `_' if you want to treat it as a partially applied function
[error] createCalculation(fromJsonVal[MyLocation](j) = {
[error] ^
这是 fromJsonVal 的方法定义
/**
* Routine to convert JValue to native type
*
* @param in JValue to convert
* @tparam T native type to extract
* @return extracted native type
*/
def fromJsonVal[T: Manifest](in: JValue): T = in.extract[T]
JValue 来自 net.liftweb/json,是:密封抽象类 JValue()extend java.lang.Object with net.liftweb.json.Diff.Diffable { <>}
更新:编译器报告此行代码中的错误
你认为我应该如何纠正这个编译错误?
createCalculation(fromJValue[MyLocation](j) = {
如果没有全貌,我认为错误只是因为您试图将输出分配给方法和缺少参数。如果没有全貌,我的猜测是你正在寻找更像的东西:
createCalculation(fromJValue[MyLocation](j)) match {
case "MyAck"....
注意j
后的双帕伦