问题描述
我有一个特质:
trait AbstractSender {
抽象SentTrigger sendMail(Mail main)
SentTrigger sentTrigger(Mail mail){
// do smth here
}
}
我有一个类:
类EmailSender实现AbstractSender {
@Override
SentTrigger sendMail(Mail mail){
//做一些事情
}
}
我尝试使用gmavenplus插件来编译它:
<插件>
< groupId> org.codehaus.gmavenplus< / groupId>
< artifactId> gmavenplus-plugin< / artifactId>
< version> 1.5< / version>
<执行次数>
<执行>
<目标>
< goal> addSources< / goal>
< goal> addTestSources< / goal>
< goal> generateStubs< / goal>
< goal>编译< / goal>
< goal> testGenerateStubs< / goal>
< goal> testCompile< / goal>
< goal> removeStubs< / goal>
< goal> removeTestStubs< / goal>
< /目标>
< /执行>
< /执行次数>
<依赖关系>
< dependency>
< groupId> org.codehaus.groovy< / groupId>
< artifactId> groovy-all< / artifactId>
<! - 任何版本的Groovy \> = 1.5.0都可以在这里工作 - >
< version> 2.4.4< / version>
< scope>运行时< / scope>
< /依赖关系>
< /依赖关系>
< / plugin>
并得到编译异常:
EmailSender不是抽象的,并且不会重写AbstractSender中的抽象方法sentTrigger
方法 sentTrigger 已实施。生成的java代码如下所示:
@ groovy.transform.Trait()public interface AbstractSender
{
;
SentTrigger sendMail(Mail mail);
sentTrigger sentTrigger(Mail mail);
}
这可以解释编译错误。我该怎么做gmavenplus插件的错误?
这不是GMavenPlus配置问题。你可以把它放到你的GroovyConsole中来演示这个
trait AbstractSender {
abstract SentTrigger发送(邮件主)
SentTrigger sentTrigger(邮件){}
}
类EmailSender实现AbstractSender {
@Override
SentTrigger sendMail(Mail mail){}
}
$ b $ class class Mail {}
class SentTrigger {}
EmailSender()
您看到的错误消息是正确的。 EmailSender
仅实现 sendMail()
,而不是 send()
。如果您将 sendMail()
重命名为 send()
,它应该可以正确编译。
I have a trait:
trait AbstractSender {
abstract SentTrigger sendMail(Mail main)
SentTrigger sentTrigger(Mail mail){
//do smth here
}
}
And I have a class:
class EmailSender implements AbstractSender{
@Override
SentTrigger sendMail(Mail mail){
//do some stuff
}
}
I try to compile it using gmavenplus plugin:
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>addSources</goal>
<goal>addTestSources</goal>
<goal>generateStubs</goal>
<goal>compile</goal>
<goal>testGenerateStubs</goal>
<goal>testCompile</goal>
<goal>removeStubs</goal>
<goal>removeTestStubs</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<!-- any version of Groovy \>= 1.5.0 should work here -->
<version>2.4.4</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</plugin>
and get compile exception:
EmailSender is not abstract and does not override abstract method sentTrigger in AbstractSender
method sentTrigger is implemented. Generated java code looks this way:
@groovy.transform.Trait() public interface AbstractSender
{
;
SentTrigger sendMail(Mail mail);
sentTrigger sentTrigger(Mail mail);
}
Which does explain compilation error. What do I do wrong with gmavenplus plugin?
解决方案 It's not a GMavenPlus configuration issue. You can put this in your GroovyConsole to demonstrate this
trait AbstractSender {
abstract SentTrigger send(Mail main)
SentTrigger sentTrigger(Mail mail) { }
}
class EmailSender implements AbstractSender{
@Override
SentTrigger sendMail(Mail mail) { }
}
class Mail { }
class SentTrigger { }
new EmailSender()
The error message you're seeing is correct. EmailSender
only implements sendMail()
, not send()
. If you rename sendMail()
to send()
, it should compile correctly.
这篇关于使用gmavenplus插件无法编译特质的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!