v31.0
版本发布时间: 2021-09-25 05:36:10
google/guava最新发布版本:v33.3.1(2024-09-24 04:55:13)
Maven
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>31.0-jre</version>
<!-- or, for Android: -->
<version>31.0-android</version>
</dependency>
Jar files
Guava requires one runtime dependency, which you can download here:
Javadoc
JDiff
Changelog
Known issue (fixed in patch release 31.0.1): guava<I>-gwt breaks GWT compilation
Other Guava artifacts aren't affected, only users of GWT. (If you are using GWT, you would know it.)
Sorry for missing this during release: It was a known issue, and we had a partial workaround in place, but I forgot to include the problem in the list of release blockers.
To pick up the fix, upgrade to 31.0.1.
Main changes
-
Changed
guava-android
to generate Java 8 bytecode. We still restrict ourselves to using APIs available on Ice Cream Sandwich. So, as long as you have enabled Java 8 language features for your Android build, this change should have no effect on Android projects. This change does drop support for Java 7 JREs, as announced last year. - Annotated Guava much more thoroughly for nullness. For details, see the bottom of the release notes.
-
base
: ChangedFunctions.forSupplier
andPredicates.instanceOf
to accept an additional type argument to specify the input type for the returnedFunction
/Predicate
. The flexibility we're adding should typically not be necessary if users follow the PECS principle, but it can be useful in some cases, particularly around nullness analysis. Note that this change may require updates to callers' source code (to specify an additional type argument). Still, it maintains binary compatibility. (75110e936d) -
collect
: AddedImmutableMap.ofEntries
, likeMap.ofEntries
but forImmutableMap
. (cd3b4197fb) -
collect
: Added overloads ofImmutableMap.of
,ImmutableBiMap.of
, andImmutableSortedMap.of
for up to 10 entries. (d5c30e3f19) -
collect
: RenamedImmutableMap.Builder.build()
tobuildOrThrow()
. The existingbuild()
method will continue to exist but may be deprecated, and the new name should be used in new code. (4bbe12c4e0) -
collect
: Removed@Beta
fromInterner
andInterners
. (cf31f3a31d) -
collect
: Added@InlineMe
toStreams.stream(Optional)
and friends. (a176cd60f1) -
graph
: MadeEndpointPair.adjacentNode
require anN
instead of accept anyObject
. (b0be21d46c) -
hash
: Removed@Beta
fromHashFunction
. (e1cc195cfb) -
hash
: Deprecated buggymurmur3_32
, and introducedmurmur3_32_fixed
. (a36f08fe31) -
io
: ChangedCharStreams.asWriter(appendable).write(string[, ...])
to reject a nullstring
. (50e7dddf5c) -
io
: Fixed a bug inFileBackedOutputStream
cleanup: If writing to the temp file fails, we now delete it before propagating the exception. (6e054cea7b) -
net
: ChangedHostAndPort.fromString
to reject port numbers spelled with non-ASCII digits. (53fd1d7612) -
net
: AddedHttpHeaders
constants forX-Device-Ip
,X-Device-Referer
,X-Device-Accept-Language
,X-Device-Requested-With
,Sec-CH-Prefers-Color-Scheme
,Sec-CH-UA-Bitness
, andKeep-Alive
. (da375be86a, b23b277422, 281edd4b6e, 9c88f9ad6d) -
primitives
: Fixed a rounding bug inUnsignedLong.doubleValue()
. (e61cf2e8d7) -
reflect
: Changed the type hierarchy ofInvokable
:Invokable
no longer inherits fromAccessibleObject
orGenericDeclaration
, though it continues to define instance methods with the same signatures as the formerly inherited ones. This is technically a breaking API change to this@Beta
API. We think it very unlikely that anyone is affected in practice. (12af215974) -
testlib
: EnhancedNullPointerTester
to allow a parameter of type<T extends @Nullable Object>
to benull
. (e85672246f) -
testlib
: Fixed bug affecting derived tests of custom collection test suites: ThesetUp
andtearDown
methods are now copied to derived test suites. (c7d9fef73b) -
util.concurrent
: AddedServiceManager.startupDurations()
. (c95ba5a298) -
util.concurrent
: Removed the GWT-only overloads ofFutures.catching
andcatchingAsync
that let callers omit theExecutor
. This matches a change made years ago to the non-GWT API. If this breaks your GWT client code compilation, you can fix it by passing an additional parameter,MoreExecutors.directExecutor()
(0ff2f78959)
Nullness annotations
Previously, we annotated all parameters that could be null
, and we did not annotate elsewhere reliably. Now:
- We consistently annotate return types for nullness.
- We annotate "components" of types, like the element type of an array or list and the bound of a type parameter. (To take advantage, Kotlin users can set
-Xtype-enhancement-improvements-strict-mode
.)- However, we don't yet annotate any such locations as non-nullable.
- In our annotations (including on parameters), we distinguish between
@Nullable T
("always nullable, regardless of the type argument used forT
") andT
("nullable only if the type argument is"). - We have temporarily increased our usage of jsr305, which we will ultimately phase out.
- We use
@CheckForNull
instead of a type-annotation@Nullable
wherever possible. This makes the nullness information available to more Kotlin users. - We've introduced a custom jsr305 annotation that informs Kotlin that unannotated return types are non-null (just like our usage of
@ParametersAreNonnullByDefault
already did for parameter types). (To take advantage, Kotlin users can set-Xjsr305=strict
.)
- We use
(Known issue: We are missing annotations on the TypeToInstanceMap
classes. We'll fix this in a future release.)
By providing additional nullness information, this release may result in more errors or warnings from any nullness analyzers you might use. If so, you may need to fix or suppress them as usual. For advice, see the documentation for the analyzer you're using, such as that for the Checker Framework or for Kotlin.
If you use NullAway with the AnnotatedPackages
flag set to cover com.google.common
, you may see not only additional legitimate errors but also some incorrect errors because Guava no longer uses @Nullable
as frequently on type-variable usages. The NullAway developers have suggested a workaround, and they are planning for NullAway 0.9.9 to treat our type-variable usages differently. However, even after 0.9.9, NullAway users are likely to see some incorrect errors if they keep com.google.common
in their AnnotatedPackages
. A fuller solution will require Guava and tools to adopt an annotation model that is more suited to generics. For updates on that, follow https://github.com/google/guava/issues/2960.
We will be using more annotations to provide more nullness information in the future.