问题
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