google / guava
Google / Guava
Guava: Google Core Libraries for Java Guava is a set of core Java libraries from Google that includes new collection types (such as multimap and multiset), immutable collections, a graph library, and utilities for concurrency, I/O, hashing, primitives, strings, and more! It is widely used on most Java projects within Google, and widely used by many other companies as well.
Guava:Google Java 核心库 Guava 是 Google 提供的一套 Java 核心库,包含多种新的集合类型(如 multimap 和 multiset)、不可变集合、图库,以及用于并发、I/O、哈希、基本类型、字符串处理等方面的实用工具!它被广泛应用于 Google 内部的大多数 Java 项目,同时也受到许多其他公司的青睐。
Guava comes in two flavors: The JRE flavor requires JDK 1.8 or higher. If you need support for Android, use the Android flavor. You can find the Android Guava source in the android directory.
Guava 提供两个版本:JRE 版本需要 JDK 1.8 或更高版本。如果您需要 Android 支持,请使用 Android 版本。您可以在 android 目录下找到 Android 版 Guava 的源码。
Adding Guava to your build
Guava’s Maven group ID is com.google.guava, and its artifact ID is guava. Guava provides two different “flavors”: one for use on a (Java 8+) JRE and one for use on Android or by any library that wants to be compatible with Android. These flavors are specified in the Maven version field as either 33.6.0-jre or 33.6.0-android. For more about depending on Guava, see using Guava in your build.
将 Guava 添加到您的构建中
Guava 的 Maven Group ID 为 com.google.guava,Artifact ID 为 guava。Guava 提供两种不同的“版本”:一种用于 (Java 8+) JRE,另一种用于 Android 或任何希望与 Android 兼容的库。这些版本在 Maven 的 version 字段中指定,分别为 33.6.0-jre 或 33.6.0-android。有关 Guava 依赖项的更多信息,请参阅“using Guava in your build”。
To add a dependency on Guava using Maven, use the following:
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>33.6.0-jre</version>
<!-- or, for Android: -->
<version>33.6.0-android</version>
</dependency>
若要使用 Maven 添加 Guava 依赖,请使用以下代码:
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>33.6.0-jre</version>
<!-- 或者,对于 Android: -->
<version>33.6.0-android</version>
</dependency>
To add a dependency using Gradle:
dependencies {
// Pick one:
// 1. Use Guava in your implementation only:
implementation("com.google.guava:guava:33.6.0-jre")
// 2. Use Guava types in your public API:
api("com.google.guava:guava:33.6.0-jre")
// 3. Android - Use Guava in your implementation only:
implementation("com.google.guava:guava:33.6.0-android")
// 4. Android - Use Guava types in your public API:
api("com.google.guava:guava:33.6.0-android")
}
For more information on when to use api and when to use implementation, consult the Gradle documentation on API and implementation separation.
若要使用 Gradle 添加依赖:
dependencies {
// 选择其一:
// 1. 仅在实现中使用 Guava:
implementation("com.google.guava:guava:33.6.0-jre")
// 2. 在公共 API 中使用 Guava 类型:
api("com.google.guava:guava:33.6.0-jre")
// 3. Android - 仅在实现中使用 Guava:
implementation("com.google.guava:guava:33.6.0-android")
// 4. Android - 在公共 API 中使用 Guava 类型:
api("com.google.guava:guava:33.6.0-android")
}
有关何时使用 api 以及何时使用 implementation 的更多信息,请查阅 Gradle 关于 API 和实现分离的文档。
Snapshots and Documentation
Snapshots of Guava built from the master branch are available through Maven using version 999.0.0-HEAD-jre-SNAPSHOT, or 999.0.0-HEAD-android-SNAPSHOT for the Android flavor. Snapshot API Javadoc as well as Snapshot API Diffs are also available. Another easy way to get to the Javadoc is to open guava.dev/api. You can also jump right to a specific class by appending the class name to guava.dev. For example, guava.dev/ImmutableList!
快照与文档
通过 Maven 可以获取从 master 分支构建的 Guava 快照版本,版本号为 999.0.0-HEAD-jre-SNAPSHOT,Android 版本则为 999.0.0-HEAD-android-SNAPSHOT。同时提供快照版 API Javadoc 以及 API 差异对比。访问 Javadoc 的另一种简便方法是打开 guava.dev/api。您还可以通过在 guava.dev 后附加类名直接跳转到特定类,例如 guava.dev/ImmutableList!
Learn about Guava
- Our users’ guide, Guava Explained
- A nice collection of other helpful links
了解 Guava
- 用户指南:Guava Explained
- 其他实用链接合集
Links
- GitHub project
- Issue tracker: Report a defect or feature request
- StackOverflow: Ask “how-to” and “why-didn’t-it-work” questions
- guava-announce: Announcements of releases and upcoming significant changes
- guava-discuss: For open-ended questions and discussion
链接
- GitHub 项目
- 问题追踪器:报告缺陷或功能请求
- StackOverflow:提问“如何实现”以及“为什么不工作”等问题
- guava-announce:发布版本更新及重大变更预告
- guava-discuss:用于开放性问题与讨论
IMPORTANT WARNINGS
APIs marked with the @Beta annotation at the class or method level are subject to change. They can be modified in any way, or even removed, at any time. If your code is a library itself (i.e., it is used on the CLASSPATH of users outside your own control), you should not use beta APIs unless you repackage them. If your code is a library, we strongly recommend using the Guava Beta Checker to ensure that you do not use any @Beta APIs!
重要警告
在类或方法级别标记为 @Beta 的 API 可能会发生变化。它们随时可能以任何方式被修改,甚至被移除。如果您的代码本身是一个库(即它被您无法控制的用户放在 CLASSPATH 中使用),除非您对这些 API 进行重新打包,否则不应使用 beta API。如果您的代码是一个库,我们强烈建议使用 Guava Beta Checker 来确保您没有使用任何 @Beta API!
APIs without @Beta will remain binary-compatible for the indefinite future. (Previously, we sometimes removed such APIs after a deprecation period. The last release to remove non-@Beta APIs was Guava 21.0.) Even @Deprecated APIs will remain (again, unless they are @Beta). We have no plans to start removing things again, but officially, we’re leaving our options open in case of surprises (like, say, a serious security problem).
没有 @Beta 标记的 API 将在未来无限期保持二进制兼容。(此前,我们有时会在弃用期后移除此类 API。上一个移除非 @Beta API 的版本是 Guava 21.0。)即使是 @Deprecated 的 API 也将保留(除非它们同时标记为 @Beta)。我们目前没有计划再次移除 API,但从官方角度来看,我们保留了应对突发情况(例如严重的安全性问题)的可能性。
Guava has one dependency that is needed for linkage at runtime: com.google.guava:failureaccess:1.0.3. It also has some annotation-only dependencies, which we discuss in more detail at that link.
Guava 有一个运行时链接所需的依赖项:com.google.guava:failureaccess:1.0.3。它还有一些仅用于注解的依赖项,我们在此链接中进行了更详细的讨论。
Serialized forms of ALL objects are subject to change unless noted otherwise. Do not persist these and assume they can be read by a future version of the library. Our classes are not designed to protect against a malicious caller. You should not use them for communication between trusted and untrusted code.
除非另有说明,否则所有对象的序列化形式都可能发生变化。请勿将它们持久化并假设未来的库版本可以读取它们。我们的类并非旨在防御恶意调用者。您不应在受信任代码与不受信任代码之间的通信中使用它们。
For the mainline flavor, we test the libraries using a range of OpenJDK versions on Linux and Windows. Some features, especially in com.google.common.io, may not work correctly in non-Linux environments. For the Android flavor, our unit tests also run on API level 24 (Nougat).
对于主线版本,我们在 Linux 和 Windows 上使用多种 OpenJDK 版本对库进行测试。某些功能(尤其是 com.google.common.io 中的功能)在非 Linux 环境中可能无法正常工作。对于 Android 版本,我们的单元测试也在 API 级别 24 (Nougat) 上运行。