Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Guava Release 21.0: Release Notes
- 21.0 was released on January 12, 2017.
- 21.0-rc2 was released on January 3, 2017.
- 21.0-rc1 was released on December 19, 2016.
- If you see errors like "cannot access com.google.errorprone.annotations.CanIgnoreReturnValue," you can work around them by adding a local dependency on
error_prone_annotations. (This problem is fixed in Guava 22, which makes that dependency present for users.)
Using Guava in your project
See UseGuavaInYourBuild for help integrating Guava into your build environment.
Important: Guava 21.0 requires Java 8. If you need Java 7 or Android compatibility, use Guava 20.0 for now. Guava 22.0 and on will introduce a Java 7/Android compatible backport of Guava that includes all of the latest changes that don't require Java 8. (As for Java 6, we don't plan to support it past 20.0.)
5+ issues are resolved in this release.
Full JDiff Report of changes since release 20.0.
Significant API additions and changes
Supplier: changed to extend the new
java.util.functioninterfaces with the same names.
fromJavaUtilmethods for easy conversion between Guava's
Objects: removed deprecated
toStringHelpermethods (both found on
MoreObjectssince Guava 18.0).
New default methods on
ConcurrentMap that were added in Java 8 are now implemented and safe to use for
Many APIs in collect now have better implementations of many of the
default methods added to
Map types in Java 8.
Comparators: With the addition of many useful methods to the
Comparatortype in Java 8,
Orderingnow provides little benefit.
Comparatorsis a new location for methods on
Orderingthat still don't have a good equivalent in the JDK.
Streams: Utility class for working with
java.util.stream.Stream. Includes methods for creating streams (such as
concat(Stream...)) and methods that do things with streams (such as
MoreCollectors: Factories for
java.util.stream.Collectorobjects; note that
Collectors for Guava's collection types are generally found on those types themselves rather than here.
Interners.InternerBuilder: Builder for
Internerinstances, with options similar to those found on
MapMaker. Created with
MapConstraints: deprecated since 19.0.
ForwardingBlockingDeque: deprecated; moved to
Immutable*types: added methods to all named
ImmutableList.toImmutableList()) which return a
Collectorfor collecting a
Streaminto an immutable collection/map object. As with most methods that create
Collectors, these are generally intended to be used as static imports.
Collectorobjects that collect to a
Collectorobjects that collect to an
toImmutableEnumSetmethod returning a
Collectorthat collects to an
Collectorobjects that collect to a
RangeSet: added default
- A number of rarely-used methods on concrete implementations of Guava collection types that aren't present on the interface they implement have been deprecated. These include:
MoreFiles: New class which contains methods similar to those in
Files, but for use with
- This includes
deleteDirectoryContentsmethods which are secure against race conditions that Java previously had no way of dealing with provided that the
SecureDirectoryStream(modern Linux versions do; Windows [NTFS at least] does not). For security, these will throw an exception if
SecureDirectoryStreamis not supported unless
RecursiveDeleteOption.ALLOW_INSECUREis passed when calling the method.
- Most classes: added
constrainToRange([type] value, [type] min, [type] max)methods which constrain the given value to the closed range defined by the
maxvalues. They return the value itself if it's within the range, the
minif it's below the range and the
maxif it's above the range.
ForwardingBlockingDeque: added; moved from
BlockingDequeis a concurrent type rather than a standard collection (it's defined in
AtomicLongMap: added a number of methods such as
accumulateAndGet(K, LongBinaryOperator)that take advantage of new Java functional types.
sameThreadExecutor(); deprecated since 18.0 in favor of