1

我正在尝试编译一个简单的 Groovy verticle,但编译器会因为它不能使用“override”关键字而绊倒。关于如何使用“override”关键字编译的verticles 有什么建议吗?

编译失败..由于它不能使用覆盖

class AppStarterGroovy extends Verticle {
    override def start() {
       ...
   }
}

>> Groovyc:意外令牌:覆盖

编译失败..由于Verticle的返回类型不同

class AppStarterGroovy extends Verticle {
    def start() {
       ...
   }
}

>> Groovyc:com.AppStarterGroovy 中 java.lang.Object start() 的返回类型与 org.vertx.java.platform.Verticle 中的 void start() 不兼容。在 [8:5]

编译好了。。

class AppStarterGroovy extends Verticle {
    void start() {
       ...
   }
}
4

1 回答 1

1

是的,Groovy 中没有override关键字,这是文档中的错误,应该删除。

但是如果这是 Groovy,并且你正在扩展Verticle,你应该扩展org.vertx.groovy.platform.Verticle

https://github.com/vert-x/mod-lang-groovy/blob/master/src/main/groovy/org/vertx/groovy/platform/Verticle.groovy

其中def start()

于 2013-11-28T09:03:04.090 回答