Does Android SDK with API 23 (Marshmallow) supports Java 8? [duplicate]

▼魔方 西西 提交于 2021-02-08 07:07:28

问题


Does IntelliJ Android Studio last update (From 30/Jan/2016) supports Java 8?

I used a lambda expression

mButton.setOnClickListener((View v) -> {
    // do something here
});

then Android Studio tells me I have an error and when I resolve the problem (Alt+spacebar) I choose the Change to Java 8 (or something like that) and it works the lambda but the libraries from Android seems to be unsupported it marks all in red.

Any options for supporting Java 8 in Android Studio?

Note: I'm using the last API Level


回答1:


No, Java 8 isn't supported. What you can do instead to write Lambdas and method references is to include retrolambda dependency to your project. Same with streams, here is a backport library. Alternatively, consider using kotlin.




回答2:


Android is using the retired Apache Harmony as its Java implementation and I believe Harmony is on Java 6, so no, Java 8 is not supported.

Java 8 will be supported in Android N though as it will use OpenJDK instead of Harmony.



来源:https://stackoverflow.com/questions/35106196/does-android-sdk-with-api-23-marshmallow-supports-java-8

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