“为什么选择 Apache Harmony"或“如何在 Android 上使用 Java 8"; [英] "Why Apache Harmony" or "How to use Java 8 on Android"

查看:19
本文介绍了“为什么选择 Apache Harmony"或“如何在 Android 上使用 Java 8";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我们大多数人都听说过 Java 8 将带来的酷炫功能,但 Android 不支持它.这是因为 Google 使用 Apache Harmony for Android.这就是阻止我们(Android 应用程序开发人员)使用 lambdas、接口中的默认实现、打开 String 等等来改进我们的代码的原因.当然,我们会处理一段时间,但是如果我们在应用程序中使用的某些库开始使用 Java 8 功能怎么办?据我所知,这是行不通的(如果有错误,请纠正我).这造成了 Standard-Java 和 Android-Java 之间的不兼容.这不可能是 Google 的意图,或者至少我想不出为什么一家开发广泛采用的操作系统的公司不想永久使用 Java 版本的原因.

Most of us have heard by now of the cool features Java 8 will bring, but Android will not support it. This is because of Google using Apache Harmony for Android. This is what is keeping us (the android app developers) from improving our code with lambdas, default implementations in interfaces, switching on a String and a lot more. Surely, we will handle for some time, but what if some libraries we use in our apps start to use Java 8 features? As far as I know, this will not work (please correct me if wrong). This creates incompatibility between Standard-Java and Android-Java. It cannot be what Google intends, or at least I can't think of a reason why a company, developing a widely adopted operating system, would wan't to permanently stay with an old Java version.

问题:

  • 他们为什么使用 Apache Harmony?
  • 为什么他们不能采用更新版本的 Java?
  • 如果他们不想要 Oracle 的 Java,为什么他们不能使用 OpenJDK 的子集(在这里许可菜鸟)?
  • 您是否知道更新所用 Java 版本的任何计划?
  • 您知道在当前的 Android 系统上使用 Java 8 类的任何方法吗?
  • Why do they use Apache Harmony?
  • Why can't they adopt a newer version of java?
  • If they don't want Oracle's Java, why can't they use a subset of OpenJDK (licensing noob here)?
  • Do you know of any plans to update the used Java version?
  • Do you know of any way to use Java 8 classes on current Android systems?

推荐答案

他们为什么使用 Apache Harmony?

Why do they use Apache Harmony?

因为 Sun 拒绝按照可接受的条款向 Google 提供 Sun(现在是 Oracle)Java 的许可.Google 和 Sun 进行了谈判,但他们最终放弃了这笔交易.

Because Sun refused to provide Google with a license for Sun (now Oracle) Java under terms that were acceptable. Google and Sun negotiated, but they ended up walking away from the deal.

Nitpick:事实上,Android 库不是 Apache Harmony.它们一开始是基于 Harmony 的,但是这两个代码库已经出现分歧.此外,Apache Harmony 项目于 2011 年 11 月正式退休".

为什么他们不能采用更新版本的 Java?

Why can't they adopt a newer version of java?

首先,Android 不运行 Java(tm).它运行一种与 Java 相同的语言,其类库在功能上等同于 Java 类库(+ Android 特定库)的子集,在具有不同 指令集.

Firstly, Android does not run Java(tm). It runs a language that is identical to Java with a class library that is functionally equivalent to a subset of the Java class library (+ Android-specific libraries), on a virtual machine with a different instruction set.

从技术角度来看,他们可以……但前提是他们投入大量精力为 Android 平台实现 Java 7 和 Java 8 语言功能、库功能等.

From a technical pespective, they could ... but only if they put in a lot of work into implementing Java 7 and Java 8 language features, library features, etc, for the Android platform.

更新 - 从 Android 19 (KitKat) 和 Eclipse ADT 22.6 开始,Android 现在支持 Java 7 语言扩展;见 http://tools.android.com/recent/eclipseadt226preview

UPDATE - As of Android 19 (KitKat) and Eclipse ADT 22.6, Android does now support the Java 7 language extensions; see http://tools.android.com/recent/eclipseadt226preview

如果他们不想要 Oracle 的 Java,为什么他们不能使用 OpenJDK 的一个子集?

If they don't want Oracle's Java, why can't they use a subset of OpenJDK?

我认为切换到 OpenJDK 不会改变任何事情.Oracle Java 和 OpenJDK 99.9% 相同.

I don't think that switching to OpenJDK would change anything. Oracle Java and OpenJDK are 99.9% the same.

无论如何,可能存在许可和相关法律问题.(要对此有所了解,请阅读甲骨文与谷歌的诉讼......这将引起上诉.)

Anyway, there may be licensing and related legal issues. (And to get a feel for that, read up on the Oracle vs Google lawsuit ... that is going to appeal.)

更有可能的是,谷歌没有看到足够的商业价值来抵消改变所需的(大规模)努力,以及它可能对 Android 生态系统造成的破坏......Android 生态系统已经受到碎片化问题的困扰.

More likely, Google doesn't see enough commercial value to counteract the (massive) effort it would take to change, and the disruption it would cause to the Android ecosystem ... which already suffers from problems with fragmentation.

您是否知道更新所用 Java 版本的任何计划?

Do you know of any plans to update the used Java version?

不,我没有.这并不意味着没有计划,但如果有,它们就不会公开.

No I don't. It doesn't mean that there aren't plans, but if there are, they are not public.

您知道在当前的 Android 系统上使用 Java 8 类的任何方法吗?

Do you know of any way to use Java 8 classes on current Android systems?

你可以移植它们.或者至少,您可以尝试移植它们.(一些 Java API 与 JVM 的本机代码方面有着密切的关系......这可能会导致移植问题.)

You could port them. Or at least, you could try to port them. (Some Java APIs have an intimate relationship with the native code side of the JVM ... and that could make porting problematic.)

这篇关于“为什么选择 Apache Harmony"或“如何在 Android 上使用 Java 8";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆