问题描述

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

参考文献

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



相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-03
  • 2021-10-31
  • 2021-12-25
  • 2022-12-23
  • 2021-05-24
猜你喜欢
  • 2022-12-23
  • 2021-06-25
  • 2021-12-27
  • 2022-01-02
  • 2022-02-16
  • 2022-12-23
相关资源
相似解决方案