首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Groovy对象继承第三方Java对象时对super的构造调用

Groovy对象继承第三方Java对象时对super的构造调用
EN

Stack Overflow用户
提问于 2016-06-18 22:44:39
回答 1查看 144关注 0票数 0

形势

我有一个Java类的Groovy子类。Java类来自依赖项,而不是我自己的本地包:

代码语言:javascript
复制
// A basic idea of the Java class' construction
public class JavaArea<PS, S> {

    public JavaArea(PS initialStyle, BiConsumer, S otheStyle, Biconsumer) {
        // constructs class...
    }

}

class GroovyArea extends JavaArea<Collection<String>, Collection<String>> {

    GroovyArea(Object unrelated arguments) {
        super(Collections.emptyList(), defaultBiConsumer, otherStyle, defaultBiConsumer)
        // do some other stuff to GroovyArea's fields
    }

}

由于某种原因,尽管构造函数调用是第一个语句,但类的编译还是失败了:Constructor call must be the first statement in a constructor.

代码语言:javascript
复制
Exception executing 
org.gradle.api.internal.tasks.compile.ApiGroovyCompiler@7a1c5b43 
in compiler daemon: 
org.gradle.api.internal.tasks.compile.CompilationFailedException: 
Compilation failed; see the compiler error output for details..

    super(Collections.emptyList(), otherParams)
          ^

Gradle构建文件

我有以下根项目的构建文件:

代码语言:javascript
复制
subprojects {
    apply plugin: 'groovy'

    repositories {
        mavenCentral()
    }

    dependencies {
        compile 'org.codehaus.groovy:groovy-all:2.4.6'

        testCompile "org.spockframework:spock-core:1.0-groovy-2.4"
        testRuntime "cglib:cglib-nodep:3.2.3"
        testRuntime "org.objenesis:objenesis:2.4"
    }
}

..。以及包含错误的实际模块的以下构建文件:

代码语言:javascript
复制
version '1.0-SNAPSHOT'

apply plugin: 'groovy'

repositories {
    maven {
        url 'https://oss.sonatype.org/content/repositories/snapshots/'
    }
}

dependencies {
    compile 'org.codehaus.groovyfx:groovyfx:0.4.0'

    compile project(':diagrammer')

    compile group: 'org.reactfx', name: 'reactfx', version: '2.0-M5'
    compile group: 'org.fxmisc.wellbehaved', name: 'wellbehavedfx', version: '0.3'
    compile (group: 'org.fxmisc.richtext', name: 'richtextfx', version: '1.0.0-SNAPSHOT') {
        exclude group:'org.reactfx', module: 'reactfx'
    }

}

我的问题

是什么导致了这个问题,我该如何解决呢?这是Groovy的一个bug吗?还是我的构建环境出了问题?

IDE: IntelliJ 2016.1.3

我不认为它是IDE,因为它正确地执行语法突出显示,并提供了正确的文档时,我悬停在'super‘关键字

级: 2.12级

Groovy: Groovy 2.4.6

我试过的

我尝试过更改Gradle (通过sdkman)和Groovy (通过构建文件)的版本。所有这些都没有解决问题:

  • 2.122.14
    • 使用Groovy:2.4.52.4.62.4.7

更新

  • 在IntelliJ中创建一个只具有重建GroovyArea类所需组件的新Gradle项目,在运行gradle build时将失败,但也会出现相同的异常。
EN

回答 1

Stack Overflow用户

发布于 2016-06-19 00:11:19

看起来是Groovy中的一个bug。作为GROOVY-7868提交

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37902304

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档