简体   繁体   English

在Groovy中实现Akka AbstractActor会产生编译器错误

[英]Implementing Akka AbstractActor in Groovy produces compiler errors

Groovy 2.4.7 here using the Akka Java API with Gradle coordinates: com.typesafe.akka:akka-actor_2.11:2.5.4 . Groovy 2.4.7在这里使用带有Gradle坐标的Akka Java API: com.typesafe.akka:akka-actor_2.11:2.5.4

I'm trying to implement an AbstractActor and running into a potential conflict between the Java/Akka API and Groovy itself: 我正在尝试实现AbstractActor并在Java / Akka API和Groovy本身之间遇到潜在的冲突:

class MyActor extends AbstractActor {
    @Override
    Receive createReceive() {
        receiveBuilder()
            .match(DoSomething, message -> {
            // Implement message handler if message is of type DoSomething
            }).build()
    }
}

Produces the following compiler error: 产生以下编译器错误:

" Groovy:expecting EOF, found ')' @ line 18, column 5. " Groovy:期望EOF,在第18行第5列中找到')'。

I think it has something to do with the -> operator used after message. 认为这与消息后使用的->运算符有关。 Is there a fix or workaround for this in Groovy-land? 在Groovy-land是否有针对此的修复程序或解决方法?

You've mixed up java's lambda expressions with groovy's closures. 您已经将Java的lambda表达式与groovy的闭包混合了。 So it should be: 因此应该是:

class MyActor extends AbstractActor {
    @Override
    Receive createReceive() {
        receiveBuilder()
            .match(DoSomething, { message ->
            // Implement message handler if message is of type DoSomething
            }).build()
    }
}

Please have a look here as well. 也请在这里看看。

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

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