Android N Java8 java.time

混江龙づ霸主 提交于 2020-01-09 05:21:32

问题


I updated to the latest Android N sdk. The only thing I don't understand is why I cannot import java.time into my code? I thought Java8 is available through Android N. Then why didn't Google add java.time package?


回答1:


Android N is not supporting all the features of Java 8. Following features are only supported:

  • Default and static interface methods
  • Lambda expressions
  • Repeatable annotations

Reflection and language-related APIs:

  • java.lang.FunctionalInterface
  • java.lang.annotation.Repeatable
  • java.lang.reflect.Method.isDefault()

and Reflection APIs associated with repeatable annotations, such as AnnotatedElement.getAnnotationsByType(Class)

Utility APIs:

  • java.util.function

For more info check the following link: http://developer.android.com/preview/j8-jack.html




回答2:


There is backport library of java.time APIs for Android that can be used

https://github.com/JakeWharton/ThreeTenABP




回答3:


java.time package was added only in API 26 (Android O):

https://developer.android.com/reference/java/time/package-summary.html



来源:https://stackoverflow.com/questions/36000997/android-n-java8-java-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!