

Show HN: Java 7 Features Backported to Android - yareally
https://github.com/yareally/Java7-on-Android

======
luke_s
Since you have to read a long way through the FAQ to find out, here are the
answers to the two most important questions I had:

    
    
       Q) So what works from Java 7?
    
       A) All the syntatic sugar stuff and also "try with resources." (see below)
    
       1) String Switches
    
       2) Try with resources (a.k.a "using/with", auto close)
    
       3) Multiple exception caught in one catch block
    
       4) Integer (and binary) literals for readability (e.g. 100_000_000 or 20_000 or 0b0111_0000)
    
       5) Type inference on collections (a.k.a. "diamonds")
    
    
       Q) What doesn't work?
    
       1) java.nio.*
    
       2) threading and multiple processor enhancements (fork/join)
    
       3) File change notifications (watch/notify file api stuff)
    
       4) invokedynamic
    
    

Its unfortunate that google haven't worked to bring more modern java language
features to Android, although I imagine that the Android group has been kept
rather busy with other things. Still, Google io is coming, with what is sure
to be a slew of new product and feature announcements, so one can hope ...

~~~
yareally
Sorry about burying the most important questions. I moved them to the top of
the FAQ now :)

I really wish Google would just make amends with the Apache Foundation and
work with them on improving OpenJDK. It would be so much better for both (and
us developers) if they did.

All the unimplemented stuff falls under more than a weekend project and not
sure how nice some of it would play with Android's APIs and Dalvik. The only
thing I would really love to see outside of what was able to easily get
working is Lambdas.

~~~
luke_s
I was following the goings on between the ASF and Sun/Oracle a while back, but
I was un-aware that ASF and google also had problems! What was the nature of
their disagreement?

I think lambdas is the one killer feature I would love to see in Android/Java
- particularly for a framework such as Androids which is so callback heavy,
lambdas would be an immense help.

~~~
yareally
I tried once more to get lambdas working, but at this point, I'm not sure if
it's a bug in the JDK as it's still in beta or if it's Android.

Log though for anyone who's less tired and curious:

<https://gist.github.com/b0d095fbd1ccd4b28fe8>

~~~
spullara
Lambdas are in JDK 8 while Android supports JDK 6. This adds support for some
of the features of JDK 7. That said, you could backport Lambda to JDK 6...

~~~
yareally
I'm sure they can be. I'm just at a dead end for the evening and way past the
time I should be programming (I was the submitter/author of the OP), thanks
though for the encouragement :)

I was just going off the educated guess (without digging through the jdk8
source) that lambdas, like most other syntax features on Java, are just
syntactical sugar that does not modify the underlying bytecode since jdk6 and
so does not require significant code changes to get it working. Though of
course I could be wrong, but I'll deal with that later on in the week.

~~~
spullara
JDK 8 implements lambda using features in JDK 7 like Invokedynamic. However,
they could be implemented as syntactic sugar on top of anonymous inner classes
— they just wouldn't be as efficient.

------
pjmlp
Nice work.

I am starting to think Google will leave Java language support at Java 6
level, or eventually offer full native support, instead of the half solution
that the NDK currently offers.

Looking forward to this year's Google IO to see if there will be any change at
that level.

~~~
koko775
It's not impossible for Google to work out a licensing deal with Oracle, but
I'd just as soon expect them to come up with their own LLVM-based language
implementation or announce LLVM support for one they've already developed,
given that they added Clang (and thus, LLVM) support to NDKv8 in November
2012.

~~~
neeee
I'd love seeing decent support for Go on Android.

~~~
pjmlp
<http://code.google.com/p/android/issues/detail?id=39482>

------
drorweiss
Well done!

On a related note - is using Scala also a viable option for android? Anybody
tried?

~~~
koko775
Sort of. It has issues with ProGuard, but the Scala standard library is a
couple of megabytes, so you'll be adding some size to your application, or
you'll have to _very_ carefully test and configure.

Additionally, Dalvik didn't have JIT until late in its maturity, so besides
the normal slowdown from Java->Scala, expect it to slow down further by the
less-efficient VM.

It might be viable on newer devices, but it'll definitely have problems on
older ones. Other than that, it does seem very feasible to write and deploy a
Scala Android app.

~~~
happy_dino
There are pretty much no issues using Scala on Android. After running
ProGuard, the Scala library takes up a few dozen kilobytes.

Execution is as fast as Java. I remember running my Scala app on one of the
first tablets (Android 2.x) without issues.

The build system support is impressive and there is a whole community which
focuses on Scala running on Android.

~~~
mhaymo
Have you built a substantial application using Scala on Android? Bump uses
Scala, and they had to do a lot of messing with build processes, and they
ended up using Java for performance in places as well. I can't find the talk
right now, but here's the slides:
[http://www.slideshare.net/michael.galpin/scala-on-android-
ex...](http://www.slideshare.net/michael.galpin/scala-on-android-experiences-
at-bump-technologies)

~~~
happy_dino
Facebook didn't use Scala and they managed do hit a lot of same issues, too,
like this one: <http://code.google.com/p/android/issues/detail?id=22586>

Anyway, the presentation is almost two years old now.

