我有一个 Grails 服务,
父类:
class BarService{
def fetchData(params) {
return fooData.toString()
}
}
子类:
class FooService extends BarService{
def fetchData(params) {
def fooData = super.fetchData(params) //this will call the BarService method
return fooData
}
}
这是正确的常规方法吗?因为对我来说这看起来像 Java
谢谢
最佳答案
根据您的示例,除了删除可选的 return
之外,无能为力。关键词:
// Parent Class:
class BarService{
def fetchData(params) {
params.fooData.toString()
}
}
// Child Class:
class FooService extends BarService{
def fetchData(params) {
super.fetchData params
}
}
assert new FooService().fetchData([fooData: 900]) == "900"
关于grails - 调用 groovy 父类方法 - Grails,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26400367/