2

我尝试使用以下代码在 Kotlin 中使用 javax.time:

import javax.time.calendar.LocalDate

fun main(args: Array<String>){
  println("Today is ${LocalDate.now()}");
}

并得到编译错误:

C:\kotlin-hello-world>kotlinc hello.kt -include-runtime -d hello.jar
hello.kt:1:14: error: unresolved reference: time
import javax.time.calendar.LocalDate
             ^

并且谷歌搜索显示 Kotlin javax.time 无法使用,人们建议如果 android使用ThreeTenBPThreeTenABP 。我的用例是在 Kotlin 的服务器端使用 javax.time 类。

但是当我尝试使用 TreeTenBP 时,我必须导入org.threeten.bp.LocalDate而不是javax.time.calendar.LocalDate因为 TreeTen* 不是 JSR-310 的实现而是反向端口。

除了那些向后移植库之外,还有什么方法可以在 Kotlin 中使用 javax.time 吗?如果是这样,如何配置这样的环境或如何编写这样的代码?

4

1 回答 1

10

javax.time是一个死包。

java.time在 Java SE 8 中使用。或org.threeten.bp用于 backport。

于 2016-07-20T18:23:35.847 回答