guava README

The project's README from github.com/google/guava. As one markdown file: README.md.

Guava: Google Core Libraries for Java

GitHub Release CI OpenSSF Best Practices

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 comes in two flavors:

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.7.1-jre or 33.7.1-android. For more about depending on Guava, see 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.7.1-jre</version>
  <!-- or, for Android: -->
  <version>33.7.1-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.7.1-jre")

  // 2. Use Guava types in your public API:
  api("com.google.guava:guava:33.7.1-jre")

  // 3. Android - Use Guava in your implementation only:
  implementation("com.google.guava:guava:33.7.1-android")

  // 4. Android - Use Guava types in your public API:
  api("com.google.guava:guava:33.7.1-android")
}

For more information on when to use api and when to use implementation, consult the Gradle documentation on API and implementation separation.

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!

Learn about Guava

IMPORTANT WARNINGS

  1. 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!

  2. 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).

  3. 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.

  4. 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.

  5. Our classes are not designed to protect against a malicious caller. You should not use them for communication between trusted and untrusted code.

  6. 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).

guava (google/guava)

Searching Database…

51.9K ·GitHub
这是什么?Guava 是 Google 推出的一组 Java 核心库,提供新的集合类型(multimap、multiset)、不可变集合、图库,以及用于并发、I/O、哈希、基本类型和字符串处理的工具类。它在 Google 内部被大量使用,许多其他公司也在用。
它是框架还是普通的工具库?它是一个作为依赖添加的工具库,不是框架,没有需要接入的应用生命周期或运行时,只是一些类和辅助方法,由你自己的代码调用。
我该如何把它加入项目?通过 Maven 或 Gradle 添加 Guava 依赖,使用组 ID com.google.guava 和构件 ID guava,并根据所需的变体选择版本后缀(例如 33.7.1-jre)。
我需要哪个 Java 版本或哪种变体?JRE 变体要求 JDK 1.8 或更高版本;如果需要 Android 支持,请改用 Android 变体,该变体还会在 API 级别 24(Nougat)上运行其测试。
使用 Guava 的 API 时有哪些需要注意的坑?标注为 @Beta 的 API 随时可能被修改或删除,因此库的作者应避免使用它们(或将其重新打包),除非使用 Guava Beta Checker;而非 @Beta 的 API 则会长期保持二进制兼容。
通常谁会使用 Guava?它面向希望使用经过充分验证的集合类型和工具类的 Java 开发者;它在 Google 内部以及许多外部公司中被广泛使用。
Guava 在 Windows 和 Linux 上的表现一样吗?大体上是一样的,但部分功能(尤其是 com.google.common.io 中的功能)在 Linux 之外的系统上可能无法正常工作;主线版本会在 Linux 和 Windows 上针对多个 OpenJDK 版本进行测试。
在不可信的代码中使用 Guava 安全吗?不安全。Guava 的类并非为防范恶意调用者而设计,因此不应将其作为可信代码与不可信代码之间的边界。
Guava 自身是否有运行时依赖?有一个:运行时链接需要 com.google.guava:failureaccess:1.0.3,此外还有一些仅用于注解的依赖,文档中有相关说明。
跨版本时,我能否依赖序列化后的 Guava 对象?不能。除非另有明确说明,所有 Guava 对象的序列化格式都可能发生变化,因此不要指望它们将来仍然兼容而将其持久化保存。
在哪里可以找到完整的 API 文档?Javadoc 位于 guava.dev/api,也可以直接跳转到具体的类,例如 guava.dev/ImmutableList;另外还有一份名为 Guava Explained 的用户指南。
已弃用(非 Beta)的 API 会怎样?它们会无限期保留在库中。Guava 自 21.0 版本起就不再删除非 @Beta 的 API,目前也没有恢复删除的计划,仅在极少数安全问题上例外。
Creator
google
Size
1.4 GB
Stars
51.9K
Age
12y
Commits · 90 Days