英文:
unable to find matching constructor for: java.time.ZonedDateTime()
问题
我有一个非常简单的代码库,但我感到非常傻。为什么会出现错误`groovy.lang.GroovyRuntimeException: Could not find matching constructor for: java.time.ZonedDateTime()`
import org.testng.annotations.Test
import java.time.ZonedDateTime
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger
class timeTests {
Logger log = LogManager.getLogger(this.class.getName())
def startTime(){
return ZonedDateTime.now()
}
def endTime(){
def start = startTime()
def end = start.plusSeconds(5)
return end
}
@Test
void test(){
log.info(endTime())
}
}
示例来源:https://www.geeksforgeeks.org/zoneddatetime-now-method-in-java-with-examples/
<details>
<summary>英文:</summary>
i have a very simple code base and i feel really silly here. Why am i getting the error `groovy.lang.GroovyRuntimeException: Could not find matching constructor for: java.time.ZonedDateTime()`
import org.testng.annotations.Test
import java.time.ZonedDateTime
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger
class timeTests {
Logger log = LogManager.getLogger(this.class.getName())
def startTime(){
return new ZonedDateTime().now()
}
def endTime(){
def start = startTime()
def end = start.plusSeconds(5)
return end
}
@Test
void test(){
log.info(endTime())
}
}
example taken from: https://www.geeksforgeeks.org/zoneddatetime-now-method-in-java-with-examples/
</details>
# 答案1
**得分**: 4
构造函数不存在。使用 `ZonedDateTime.now()` 函数或其等效函数之一。请参阅相关的 [JavaDoc](https://docs.oracle.com/javase/8/docs/api/java/time/ZonedDateTime.html)。
<details>
<summary>英文:</summary>
The constructor does not exist. Use `ZonedDateTime.now()` or one of the equivalents. See the relevant [JavaDoc](https://docs.oracle.com/javase/8/docs/api/java/time/ZonedDateTime.html).
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论