-1

以下代码不起作用: FileSystems.getDefault.getPath 来自 java.nio 包

更新:

方法 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
  }

//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:  %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 并且是:sealed abstract class JValue()extends java.lang.Object with net.liftweb.json.Diff.Diffable { <> }

更新:编译器报告错误在这行代码中

你认为我应该如何纠正这个编译错误?

   createCalculation(fromJValue[MyLocation](j) = {
4

1 回答 1

0

如果没有全貌,我认为错误仅仅是因为您试图将输出分配给方法并且缺少括号。如果没有全貌,我的猜测是您正在寻找更像:

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

注意后面的双括号j

于 2015-04-17T01:57:49.997 回答