5 ms·
Dalvik is being slowly replaced by ART (Android RunTime). Also, you can pretty easily hack Java 7 or even Java 8 into Android to use lambdas. Official, default
by mncolinlee 12y ago
Dalvik is being slowly replaced by ART (Android RunTime). Also, you can pretty easily hack Java 7 or even Java 8 into Android to use lambdas. Official, default support is coming soon.
http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Using-sourceCompatibility-1.7 http://tools.android.com/tech-docs/new-build-system/user-gui...
http://zserge.com/blog/android-lambda.html http://zserge.com/blog/android-lambda.html
- pjmlp 12y agoExcept those lambdas are not as efficient as the standard compliants VMs, as they make use of invokedynamic to generate better code, even inline calls for small lambdas.
- Groxx 12y agoWhich might be fixable with ART as it's an on-device ahead-of-time compiler (I think it optimizes too? can't find references...). I have no idea if it actually does work for this in practice or not, though.
- pjmlp 12y agoTrue, but it won't help users with KitKat and lower devices. We all know that they won't see any vendor updates.
- Groxx 12y agoWell sure. But people don't update their Java installs either, neither do all businesses. They're likely not going to be able to take advantage of v8 stuff. And can dumbphones on a Java platform (Symbian? Nokia? Others?) run the new Java flashiness? Every platform has problems like this.
- georgewfraser 12y agoAre you sure about that? I've looked at the way invokedynamic generates lambdas, and it's just generating anonymous classes at runtime using ASM. Inlining is from the JIT and applies to anonymous classes as well. I'm pretty sure you can get the exact same results without invokedynamic, you just have a lot more .class files to distribute.
- pjmlp 12y agoI am basing my comment on the Java One talk about Java 8 lambdas implementation on the Oracle JVM. I assume other certified JVMs would follow similar design approaches.
- sixbrx 12y agoI think you got it right. According to Grzegorz Kossakowski's comment (which is more accurate than the misleading article) : http://www.takipiblog.com/2014/01/16/compiling-lambda-expressions-scala-vs-java-8/ http://www.takipiblog.com/2014/01/16/compiling-lambda-expres... , Java 8's lambda's aren't particularly efficient. They do create an anonymous class instance at runtime, as you say. Scala closures are implemented in a similar way, without invokedynamic, and as he says, and currently there is no performance win from invokedynamic's use in Java 8 vs the Scala impl. But it does hold promise of future optimizations, as he says: "However, the key thing about invokedynamic is that it's essentially a JVM-level macro that defers lambda translation strategy to LambdaMetaFactory which is a library class. If Java 9 or 10 gets more direct (and performant) support for lambdas that won't require classes and object allocations then it can swap implementation of LambdaMetaFactory and all _existing_ code written for Java 8 will get performance boost. That is the brilliance of using invokedynamic in context of translating lambdas. We'll have to wait for future versions of Java to experience those benefits, though."
- spullara 12y agoI don't think that person understands how it works at all.
- llemiengre 12y agoHe knows what he is talking about & his description matches the explanation by Brian Goetz. So unless I'm missing something, please be specific.
- spullara 12y agoWell, for one, Lambdas are desugared into methods, not anonymous classes. Early on they used anonymous classes because it was convenient but that wasn't the final translation strategy. http://cr.openjdk.java.net/~briangoetz/lambda/lambda-translation.html http://cr.openjdk.java.net/~briangoetz/lambda/lambda-transla...
- nl 12y agoBut it allows people to move forward using the syntax itself. The implementation can be optimised at any point.
- clumsysmurf 12y ago>> Official, default support is coming soon. Default support of ART or Java 8? If Java 8, how do you know this? Citation needed ;)
- mncolinlee 12y agoJava 8. Arguing whether Java 8 will be completely supported or not ignores the nature of the Android API. Android doesn't even support 100% of Java 6 because it is not a desktop JDK and does not intend to replicate everything. However, the Android team has actively been adding default support of Java 7 features piece by piece in recent months. They intend to handle Java 8 in the same manner. It's not clear which features will be supported in what version of Android, but lambdas are clearly a priority and can already be used today by early adopters using retrolambda. http://stackoverflow.com/a/22303654/1412973 http://stackoverflow.com/a/22303654/1412973