2015-04-17 17 views
-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) = { 

回答

0

不完整的图片,我认为错误是仅仅从你想输出分配给一个方法,而遗漏的括号。如果没有完整的图片,我的猜测是,你正在寻找更多的东西一样:

createCalculation(fromJValue[MyLocation](j)) match { 
    case "MyAck".... 

注意双括号后j

+0

我会加入更多内容,我加入了更多细节的问题 – user3825558

+0

码。 val是一个PartialFunction – user3825558

+0

您的更正没有帮助:我现在得到的错误是:“type mismatch:expected:MyLocation,actual:Unit – user3825558