原文地址:Apache Groovy——java.lang.NoSuchMethodError: x.x.x: method ()V not found(永久地址,保存网址不迷路 🙃)
问题描述
在执行 Groovy 代码中,产生如下错误:
ava.lang.NoSuchMethodError: com.lispstudio.model.TeamLispstudio: method <init>()V not found
问题原因
在继承父类之后,没调用父类的构造函数。
解决方法
有两种解决方法:1)调用与父类相同的构造函数;2)使用 InheritConstructors 注解;
调用与父类相同的构造函数
class Creature {
Creature (String feature) {}
}
class Humman extends Creature{
Humman (String feature) {
super(feature)
}
}
new Humman("legs")
使用 InheritConstructors 注解
class Creature {
Creature (String feature) {}
}
@groovy.transform.InheritConstructors
class Humman extends Creature{
}
new Humman("legs")
相关文章
「Groovy」- Unable to load extension class
「Groovy」- java.sql.SQLException: Incorrect string value: 'xxx","...' for column 'xxx' at row 1
参考文献
<init>()V not found when defining superclass constructor
InheritConstructors (groovy 2.4.9 API)
本文介绍了在Apache Groovy编程时遇到`java.lang.NoSuchMethodError`的问题,详细分析了该错误产生的原因——没有在子类中调用父类构造函数,并提供了两种解决方案:调用父类的相同构造函数或使用`InheritConstructors`注解。同时还提及了相关文章和参考资料,帮助开发者解决问题。
3416

被折叠的 条评论
为什么被折叠?



