无法找到匹配的构造函数: java.time.ZonedDateTime()。

huangapple go评论99阅读模式
英文:

unable to find matching constructor for: java.time.ZonedDateTime()

问题

  1. 我有一个非常简单的代码库但我感到非常傻为什么会出现错误`groovy.lang.GroovyRuntimeException: Could not find matching constructor for: java.time.ZonedDateTime()`
  2. import org.testng.annotations.Test
  3. import java.time.ZonedDateTime
  4. import org.apache.logging.log4j.LogManager
  5. import org.apache.logging.log4j.Logger
  6. class timeTests {
  7. Logger log = LogManager.getLogger(this.class.getName())
  8. def startTime(){
  9. return ZonedDateTime.now()
  10. }
  11. def endTime(){
  12. def start = startTime()
  13. def end = start.plusSeconds(5)
  14. return end
  15. }
  16. @Test
  17. void test(){
  18. log.info(endTime())
  19. }
  20. }

示例来源:https://www.geeksforgeeks.org/zoneddatetime-now-method-in-java-with-examples/

  1. <details>
  2. <summary>英文:</summary>
  3. 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()`
  4. import org.testng.annotations.Test
  5. import java.time.ZonedDateTime
  6. import org.apache.logging.log4j.LogManager
  7. import org.apache.logging.log4j.Logger
  8. class timeTests {
  9. Logger log = LogManager.getLogger(this.class.getName())
  10. def startTime(){
  11. return new ZonedDateTime().now()
  12. }
  13. def endTime(){
  14. def start = startTime()
  15. def end = start.plusSeconds(5)
  16. return end
  17. }
  18. @Test
  19. void test(){
  20. log.info(endTime())
  21. }
  22. }
  23. example taken from: https://www.geeksforgeeks.org/zoneddatetime-now-method-in-java-with-examples/
  24. </details>
  25. # 答案1
  26. **得分**: 4
  27. 构造函数不存在。使用 `ZonedDateTime.now()` 函数或其等效函数之一。请参阅相关的 [JavaDoc](https://docs.oracle.com/javase/8/docs/api/java/time/ZonedDateTime.html)。
  28. <details>
  29. <summary>英文:</summary>
  30. 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).
  31. </details>

huangapple
  • 本文由 发表于 2020年8月24日 23:01:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/63563576.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定