我正在尝试始终如一地使用 Java 8 日期时间 API,我正在寻找这种行为背后的解释:
Instant.from(LocalDateTime.of(2017,01,01,0,0,0,0))
编译得很好,但产生:
Exception in thread "main" java.time.DateTimeException: Unable to obtain Instant from TemporalAccessor: 2017-01-01T00:00 of type java.time.LocalDateTime
我的问题是:如果这些类型不兼容,为什么 API 让我编写代码并编译它而不用尖叫?