【发布时间】:2022-02-07 21:38:38
【问题描述】:
我是 Java 和 groovy 的新手,我主要使用 Python 编写代码。我试图理解为什么代码不起作用。
我得到的错误是
groovy.lang.MissingMethodException: No signature of method: static HelloWorld.TestingProduct() is applicable for argument types: () values: []
我的任务是在项目中添加 eventdate 作为 sysdate,我只是想了解如何通过本地测试来添加它
import groovy.transform.ToString
import java.time.OffsetDateTime
import java.time.format.DateTimeFormatter
public class HelloWorld{
public static void main(String[] args){
String testin = TestingProduct().Inventory()
System.out.println(testin);
}
}
class Parent {
private String setDateNow() {
OffsetDateTime now = OffsetDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE_TIME;
return formatter.format(now);
}
}
class TestingProduct extends Parent {
private static ProductInventoryEvent Inventory(){
def invent = new ProductInventoryEvent(
productId:'1',
productIdType:'2',
eventType:'3',
eventDate: setDateNow(),
)
return invent
}
}
@Canonical()
@ToString(includeNames = true)
class ProductInventoryEvent {
String productId
String productIdType
String eventType
String eventDate
}
【问题讨论】:
-
TestingProduct是一个类。要创建新类,您必须使用new关键字:new TestingProduct()。没有new- 这是一个函数/方法调用。 -
我试过
new,现在我得到了groovy.lang.MissingMethodException: No signature of method: static TestingProduct.setDateNow() is applicable for argument types: () values: []