「Apache Groovy」- java.lang.NoSuchMethodError: x.x.x: method <init>()V not found @20210223

本文探讨了在Groovy中遇到的‘<init>()V not found’错误,重点介绍了未调用父类构造函数导致的问题,以及如何通过调用相同构造函数或使用InheritConstructors注解来修复。实例代码演示了两种解决方案并给出了相关API参考。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题描述

在执行 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

参考文献

<init>()V not found when defining superclass constructor
InheritConstructors (groovy 2.4.9 API)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值