简体   繁体   English

定义Lagom服务实现时需要保留Scala编译时错误

[英]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). 我已经在Java上使用lagom一段时间了,但没有遇到任何问题,但是我一直在努力使其与scala一起使用(公开-因为我对scala相当陌生,所以我可能会做些愚蠢的事情)。

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. 我已经定义了一个(非常)最小的lagom服务(下面),该服务不会引起任何问题,但是我在实现代码中遇到了scala编译时错误“ undersing parameter type ”作为下划线参数,我不明白为什么。 ...我以为scala隐式键入应该做必要的工作,但显然我错了。

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): 这是我的服务接口(API)定义(在文件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: 这是导致编译器错误的实现定义(在文件MyService-impl / MyTestServiceImpl.scala中):

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() . 如果您粘贴确切的错误输出会很好,但是问题是您将myTest2定义为采用String的方法,即def myTest2(cmd: String) ,但随后您将其实现为采用def myTest2(cmd: String)的方法。没有参数,即override def myTest2() Change it to override def myTest2(cmd: String) and that will fix your problem. 更改它以override def myTest2(cmd: String) ,这将解决您的问题。

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 . 出现特定错误的原因是,因为您实际上并未覆盖定义的myTest2方法,所以Scala编译器无法推断您打算返回的ServiceCall的类型,因此无法在您传递给ServiceCall的lambda中推断参数的类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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