简体   繁体   中英

Need held with scala compile time error when defining a lagom service implementation

I've been using lagom with Java for some time without problems, but am struggling to get it to work with scala (disclosure - since I am fairly new to scala, I am probably doing something daft).

I have defined a (very) minimal lagom service (below) which should not cause any problems, but I am getting the scala compile-time error " missing parameter type " for the underscore parameter in the implementation code and I do not understand why.... I thought that the scala implicit typing should do the necessary but obviously I am wrong.

Can anybody help? I am probably doing something stupid, but for the life of me I cannot see what.

Regards, Rick

This is my service interface (API) definition (in the file MyService-api/MyTestService.scala):

trait MyTestService extends Service {

def myTest2(cmd: String) : ServiceCall[NotUsed, String] // (abstract) method definition

override final def descriptor = {                       // Service Descriptor
        import Service._
        named("myTest2")                                // service name
        .withCalls {                    
        pathCall("myTest/:cmd", myTest2 _)              // will become the REST URI
        }
        .withAutoAcl(true)
    }
}

and this is the implementation definition (in the file MyService-impl/MyTestServiceImpl.scala) that is causing the compiler error:

class MyTestServiceImpl extends MyTestService {
    // this is where the error happens....
    override def myTest2() = ServiceCall { _ => Future.successful("Hi MyTest2 user") }  
                                           ^
                                           ^ 
                                         (here)
}

It would be good if you pasted the exact error output, but the problem is that you defined myTest2 to be a method that takes a String , ie def myTest2(cmd: String) , but then you've implemented it as a method that takes no parameters, ie override def myTest2() . Change it to override def myTest2(cmd: String) and that will fix your problem.

The reason for the specific error you're getting is that because you're not actually overriding the myTest2 method as defined, the Scala compiler can't infer the type of ServiceCall that you're meant to be returning, and hence can't infer the type of the parameter in the lambda that you're passing to ServiceCall .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM