56

I understand that the "java" in a dalvik vm is different from Java se in terms of API and architecture etc. But the syntax has always been the same. (Please correct me if I am wrong)

Now the support of lambda expression in java 8 is about to be released, will android java follow it? did google or aosp promise on making dalvik consistent with java se?

UPDATE: Now as in Android 4.4 Kit Kat (API 19), Java 7 syntax has been OFFICIALLY supported.Source from android.com

Fermat's Little Student
  • 5,549
  • 7
  • 49
  • 70
  • Caveat. I don't know - but would the VM need to change? As I understand it, lambdas are known only to the compiler. Under the covers, it's just a way of expressing an anonymous method - I think...Try this - http://www.lambdafaq.org/ The big change is to add support to all of the generics. – Simon Feb 11 '13 at 18:47
  • 16
    Why is it that almost every question I find interesting on SO has been closed? Is there some kind of bizarre competition to close the maximum number of questions? – Ross Judson Mar 05 '14 at 15:39
  • 1
    @RossJudson - The problem is that most of the "interesting" questions are those for which there is no real objective answer. The aim, of SO is to provide objective answers ... not to *"solicit debate, arguments, polling, or extended discussion"*. And no, there is not a competition. And no ... voting to close questions doesn't increase your reputation. – Stephen C Mar 29 '14 at 04:33
  • 1
    @RossJudson - For what it is worth, there are a myriad other places where such questions could be asked and answered. Perhaps you should be asking (yourself) why they are not as popular / successful as SO ... 'cos maybe that will give you a hint as to why Questions like this get closed here ... – Stephen C Mar 29 '14 at 04:39
  • 6
    This is a very constructive question. – Gerard Jul 03 '14 at 13:32

1 Answers1

33

Android doesn't use Oracle's Java SE versions, it's based on parts of the Apache Harmony project so it doesn't even support Java 7. Harmony is not actively developed any more and won't support 1.7.

Unless Google decides to upgrade Harmony and the Android SDK to a newer Java version, there won't be any Java 7 or Java 8 features in Android - even if new features are just syntactical. They could use an alternative implementation like the OpenJDK, though I don't know of any plans for this. Some people think the use of OpenJDK is unlikely because of lawsuits between Google and Oracle.


Some features of Java 7, most notable: diamond operators, multi-catch, string switch and in Android N also some Java 8 features like lambda expressions have been implemented in Android since this answer was written. (Thanks to Ross and Stefan for mentioning it in the comments).

Google has to implement those features by their own effort and it seems that the choose to do so mostly for more popular features.

Community
  • 1
  • 1
kapex
  • 28,903
  • 6
  • 107
  • 121
  • 5
    Recent Android SDKs have rendered this answer incorrect. Java 7 syntax is supported. – Ross Judson Apr 21 '14 at 16:04
  • 3
    Some Java 7 features are now available. The main point still stands: Google can't just switch to Java 8 without some great effort and needs to implement those features on their own. They decided to do this for parts of Java 7 but it seems they still don't really communicate any plans for supporting Java 8. Here is another question on this topic with an excellent answer: http://stackoverflow.com/q/16921337/897024 – kapex Apr 21 '14 at 20:19
  • 4
    Android N is moving to OpenJDK. The java.util.function package has been merged into the AOSP libcore master today. That includes interface default methods and the use of lambda expressions. Having a quick look at this AOSP toolchain/jack commit suggests that the new "Jack" compiler can indeed rewrite lambda expressions: http://bit.ly/1KUvqm6 To my knowledge, the collections code in the Git master is still based on OpenJDK 7. So, no signs of a Stream API yet. – Stefan Zobel Feb 16 '16 at 18:07
  • 2
    Here is the official confirmation that Android N is going to support Java 8: http://developer.android.com/preview/j8-jack.html Streams are still missing but java.util.Spliterator(s) has been integrated yesterday. Given the current pace, I'd expect we'll see the Stream API in May. – Stefan Zobel Mar 11 '16 at 13:01
  • 2
    The java.util.stream package has been merged into the AOSP libcore master today. – Stefan Zobel Mar 18 '16 at 13:15
  • Luckily we won't need this in a few weeks. Android will have full support for Java 8 language features. Jack will be deprecated. More details here: https://android-developers.googleblog.com/2017/03/future-of-java-8-language-feature.html – YYamil Mar 15 '17 at 17:47