-
Couldn't load subscription status.
- Fork 11.1k
Release21
- 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.
(See ReleaseHistory.)
API documentation:
- 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.)
| Guava | Guava (GWT) | |
|---|---|---|
| Maven Identifier | com.google.guava:guava:21.0 | com.google.guava:guava-gwt:21.0 |
| Jar | guava-21.0.jar | guava-gwt-21.0.jar |
| Javadoc | guava-21.0-javadoc.jar | guava-gwt-21.0-javadoc.jar |
| Sources | guava-21.0-sources.jar | guava-gwt-21.0-sources.jar |
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.
-
Function,PredicateandSupplier: changed to extend the newjava.util.functioninterfaces with the same names. -
Optional: addedtoJavaUtilandfromJavaUtilmethods for easy conversion between Guava'sOptionalandjava.util.Optional. -
Objects: removed deprecatedfirstNonNullandtoStringHelpermethods (both found onMoreObjectssince Guava 18.0).
New default methods on ConcurrentMap that were added in Java 8 are now implemented and safe to use for Cache.asMap() views.
Many APIs in collect now have better implementations of many of the default methods added to Collection and Map types in Java 8.
-
Comparators: With the addition of many useful methods to theComparatortype in Java 8,Orderingnow provides little benefit.Comparatorsis a new location for methods onOrderingthat still don't have a good equivalent in the JDK. -
Streams: Utility class for working withjava.util.stream.Stream. Includes methods for creating streams (such asstream(Iterable),stream(Optional)andconcat(Stream...)) and methods that do things with streams (such asfindLast(Stream)). -
MoreCollectors: Factories forjava.util.stream.Collectorobjects; note thatCollectors for Guava's collection types are generally found on those types themselves rather than here. -
Interners.InternerBuilder: Builder forInternerinstances, with options similar to those found onMapMaker. Created withInterners.newBuilder().
-
MapConstraintandMapConstraints: deprecated since 19.0.
-
FluentIterable: addedstream()method. -
ForwardingBlockingDeque: deprecated; moved toutil.concurrent. -
Immutable*types: added methods to all namedtoImmutable[Type]()(e.g.ImmutableList.toImmutableList()) which return aCollectorfor collecting aStreaminto an immutable collection/map object. As with most methods that createCollectors, these are generally intended to be used as static imports. -
Multimap: addedforEach(BiConsumer)method. -
Multimaps: addedtoMultimapandflatteningToMultimapmethods returningCollectorobjects that collect to aMultimap. -
Multiset: addedforEachEntry(ObjIntConsumer)method. -
Maps: addedtoImmutableEnumMapmethods returningCollectorobjects that collect to anImmutableMapwithenumkeys. -
Sets: addedtoImmutableEnumSetmethod returning aCollectorthat collects to anImmutableSetofenums. -
Tables: addedtoTablemethods returningCollectorobjects that collect to aTable. -
RangeSet: added defaultaddAll(Iterable<Range>),removeAll(Iterable<Range>)andenclosesAll(Iterable<Range>)methods. -
ImmutableRangeSet: addedcopyOf(Iterable<Range>),unionOf(Iterable<Range>),union(RangeSet),intersection(RangeSet)anddifference(RangeSet)methods. -
TreeRangeSet: addedcreate(Iterable<Range>)method. - 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:
ArrayListMultimap.trimToSize(),TreeMultimap.keyComparator(), andTreeBasedTable.row/columnComparator().
-
MoreFiles: New class which contains methods similar to those inFiles, but for use withjava.nio.file.Pathobjects. - This includes
deleteRecursivelyanddeleteDirectoryContentsmethods which are secure against race conditions that Java previously had no way of dealing with provided that theFileSystemsupportsSecureDirectoryStream(modern Linux versions do; Windows [NTFS at least] does not). For security, these will throw an exception ifSecureDirectoryStreamis not supported unlessRecursiveDeleteOption.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 theminandmaxvalues. They return the value itself if it's within the range, theminif it's below the range and themaxif it's above the range.
-
ForwardingBlockingDeque: added; moved fromcommon.collectbecauseBlockingDequeis a concurrent type rather than a standard collection (it's defined injava.util.concurrent). -
AtomicLongMap: added a number of methods such asaccumulateAndGet(K, LongBinaryOperator)that take advantage of new Java functional types. -
Monitor: addednewGuard(BooleanSupplier). -
MoreExecutors: removedsameThreadExecutor(); deprecated since 18.0 in favor ofdirectExecutor()(preferable) ornewDirectExecutorService().
- Introduction
- Basic Utilities
- Collections
- Graphs
- Caches
- Functional Idioms
- Concurrency
- Strings
- Networking
- Primitives
- Ranges
- I/O
- Hashing
- EventBus
- Math
- Reflection
- Releases
- Tips
- Glossary
- Mailing List
- Stack Overflow
- Android Overview
- Footprint of JDK/Guava data structures