Java 在集成类中找不到匹配的构造函数

Java 在集成类中找不到匹配的构造函数,java,groovy,Java,Groovy,我在内部类功能中定义了一个构造函数,但是我得到无法找到与:C$Feature(java.lang.String)匹配的构造函数,下面是我的代码: class C { class Feature { Feature(String ext) { this.ext = ext } String ext } } class C2 extends C { def m() { new Featu

我在内部类功能中定义了一个构造函数,但是我得到
无法找到与:C$Feature(java.lang.String)
匹配的构造函数,下面是我的代码:

class C {
    class Feature {
        Feature(String ext) {
            this.ext = ext
        }
        String ext
    }
}

class C2 extends C {
    def m() {
        new Feature("smth")
    }
}

class RoTry {
    static void main(String[] args) {
        new C2().m()
    }
}
更新 我的groovy版本是

------------------------------------------------------------
Gradle 2.3
------------------------------------------------------------

Build time:   2015-02-16 05:09:33 UTC
Build number: none
Revision:     586be72bf6e3df1ee7676d1f2a3afd9157341274

Groovy:       2.3.9
Ant:          Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM:          1.8.0_05 (Oracle Corporation 25.5-b02)
OS:           Linux 3.13.0-24-generic amd64

非私有内部类需要构造函数中的形式参数:请参阅

因此,在方法
m()
中,您应该使用
新功能(此“smth”)

通过反射,您可以看到:

C.Feature.class.getDeclaredConstructors().each { constructor ->
    println constructor
}

--

public C$Feature(C,java.lang.String)

如果不创建a的实例,您可能无法创建一个功能。请尝试将其放在您的
m
方法中:
new C.Feature(new C(),“smth”)
我尝试了您的代码,如果您删除了它编译的语法错误……这应该是
new C.Feature(“smth”)
这是我找到的最好的方法
C.Feature.class.getDeclaredConstructors().each { constructor ->
    println constructor
}

--

public C$Feature(C,java.lang.String)