繁体   English   中英

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

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

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

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

这是导致编译器错误的实现定义(在文件MyService-impl / MyTestServiceImpl.scala中):

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

如果您粘贴确切的错误输出会很好,但是问题是您将myTest2定义为采用String的方法,即def myTest2(cmd: String) ,但随后您将其实现为采用def myTest2(cmd: String)的方法。没有参数,即override def myTest2() 更改它以override def myTest2(cmd: String) ,这将解决您的问题。

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

暂无
暂无

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

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