开发者

How does Android's Java version relate to a Java SE version?

开发者 https://www.devze.com 2023-04-06 21:50 出处:网络
I am constantly wondering how the Java version used for Android development relates to a Java SE version.For example, I was reading today about \"Type Inference and Generic Methods\" which is a featur

I am constantly wondering how the Java version used for Android development relates to a Java SE version. For example, I was reading today about "Type Inference and Generic Methods" which is a feature added in Java 开发者_StackOverflow社区SE 7. I wonder to myself, "Can I use this in Android code?"

Of course I could type the code into an Android project and see if it compiles, but I'd be happier to have some kind of mapping in my head.

I've tried Googling for this info, checking the Android docs, etc, but can't find an answer.

Edit: I'm more interested in language features, e.g. how does the Android Java syntax version relate to Java SE syntax.


Android's version doesn't directly relate to Java SE, although it uses a subset of Apache Harmony's SE 6 libraries and tools. It will be up to the Android team to decide if & when to support/require the SE 7 version of Harmony.

Edit It looks like as of KitKat Android supports Java SE 7 language features. See the comments below.


There is no direct mapping:

  • Some parts of the API (such as JAXB, which has been around since at least Java 6) have never been available on Android.
  • When features of a new Java version are introduced, this can happen gradually over multiple versions.
  • Some newer Java features are made available for older, already-released versions as backports.

In the past it has taken Google some 2–3 years to start adopting a new Java version. Java 7 features started appearing around API 19 (KitKat). Java 8 features started at API 26 (Nougat), but a mechanism called desugaring is available to make certain Java 8 features available on earlier Android versions, regardless of their API level.

So, generally speaking, if you want to know whether a particular Java API feature is available on Android, look it up on the Android developer reference and check the minimum API version.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号