-1
下面這段代碼不起作用: FileSystems.getDefault.getPath是java.nio包斯卡拉:部分功能錯誤:使用_如果你想要把它當作一個PartialFunction
更新:
方法createCalculation是:
注: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
}
//所需物品是從類的情況下,類: 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: %s\n", myKey, myValue)
}
}
})
}) ("Failed to calculate")
}
編譯器會抱怨這樣的:
[error] C:\Users\lulu\ExampleHandler.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()使用net.liftweb.json.Diff.Diffable擴展java.lang.Object { <> }
更新:編譯器報告錯誤在這行代碼
你覺得我應該糾正這個編譯錯誤?
createCalculation(fromJValue[MyLocation](j) = {
我會加入更多內容,我加入了更多細節的問題 – user3825558
碼。 val是一個PartialFunction – user3825558
您的更正沒有幫助:我現在得到的錯誤是:「type mismatch:expected:MyLocation,actual:Unit – user3825558