---
title: 'Google Guava steigt (endlich) auf Java 8 um'
url: 'https://tutego.de/blog/javainsel/2017/02/google-guava-steigt-endlich-auf-java-8-um'
markdown: 'https://tutego.de/blog/javainsel/2017/02/google-guava-steigt-endlich-auf-java-8-um.md'
date: '2017-02-01'
description: 'Die News unter : Significant API additions and changes common.base Function, Predicate and Supplier: changed to extend the new java.util.functioninterfaces with the same names. Optional: added toJavaUtil and fromJavaUtil methods for easy conversion between Guava’s Optional and java.util.Optional. …'
taxonomy:
  category:
    - Allgemein
    - 'Guava/Google Core Libraries'
    - 'Open Source'
---

# Google Guava steigt (endlich) auf Java 8 um

![Illustration einer tropischen Insel mit Palmen und einem hohen Berg](https://tutego.de/blog/javainsel/user/themes/tutego/images/insel-cover.jpg)# Java Blog für Programmierer

[Java Blog für Programmierer](https://tutego.de/blog/javainsel/)

## Google Guava steigt (endlich) auf Java 8 um

01.02.2017 · [Christian Ullenboom](https://tutego.de/blog/javainsel/author/admin/)

Die News unter :

## Significant API additions and changes

### common.base

- `Function`, `Predicate` and `Supplier`: changed to extend the new `java.util.function`interfaces with the same names.
- `Optional`: added `toJavaUtil` and `fromJavaUtil` methods for easy conversion between Guava’s `Optional` and `java.util.Optional`.
- `Objects`: removed deprecated `firstNonNull` and `toStringHelper` methods (both found on `MoreObjects` since Guava 18.0).

### common.cache

New default methods on `ConcurrentMap` that were added in Java 8 are now implemented and safe to use for `Cache.asMap()` views.

### common.collect

Many APIs in collect now have better implementations of many of the `default` methods added to `Collection` and `Map` types in Java 8.

#### New classes

- `Comparators`: With the addition of many useful methods to the `Comparator` type in Java 8, `Ordering` now provides little benefit. `Comparators` is a new location for methods on `Ordering`that 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 `stream(Iterable)`, `stream(Optional)` and `concat(Stream...)`) and methods that do things with streams (such as `findLast(Stream)`).
- `MoreCollectors`: Factories for `java.util.stream.Collector` objects; note that `Collector`s for Guava’s collection types are generally found on those types themselves rather than here.
- `Interners.InternerBuilder`: Builder for `Interner` instances, with options similar to those found on `MapMaker`. Created with `Interners.newBuilder()`.

#### Removed classes

- `MapConstraint` and `MapConstraints`: deprecated since 19.0.

#### Changes

- `FluentIterable`: added `stream()` method.
- `ForwardingBlockingDeque`: deprecated; moved to `util.concurrent`.
- `Immutable*` types: added methods to all named `toImmutable[Type]()` (e.g. `ImmutableList.toImmutableList()`) which return a `Collector` for collecting a `Stream` into an immutable collection/map object. As with most methods that create `Collector`s, these are generally intended to be used as static imports.
- `Multimap`: added `forEach(BiConsumer)` method.
- `Multimaps`: added `toMultimap` and `flatteningToMultimap` methods returning `Collector`objects that collect to a `Multimap`.
- `Multiset`: added `forEachEntry(ObjIntConsumer)` method.
- `Maps`: added `toImmutableEnumMap` methods returning `Collector` objects that collect to an `ImmutableMap` with `enum` keys.
- `Sets`: added `toImmutableEnumSet` method returning a `Collector` that collects to an `ImmutableSet` of `enum`s.
- `Tables`: added `toTable` methods returning `Collector` objects that collect to a `Table`.
- `RangeSet`: added default `addAll(Iterable)`, `removeAll(Iterable)` and `enclosesAll(Iterable)` methods.
- `ImmutableRangeSet`: added `copyOf(Iterable)`, `unionOf(Iterable)`, `union(RangeSet)`, `intersection(RangeSet)` and `difference(RangeSet)` methods.
- `TreeRangeSet`: added `create(Iterable)` 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()`, and `TreeBasedTable.row/columnComparator()`.

### common.io

- `MoreFiles`: New class which contains methods similar to those in `Files`, but for use with `java.nio.file.Path` objects.
- This includes `deleteRecursively` and `deleteDirectoryContents` methods which are secure against race conditions that Java previously had no way of dealing with provided that the `FileSystem` supports `SecureDirectoryStream` (modern Linux versions do; Windows \[NTFS at least\] does not). For security, these will throw an exception if `SecureDirectoryStream` is not supported unless `RecursiveDeleteOption.ALLOW_INSECURE` is passed when calling the method.

### common.primitives

- Most classes: added `constrainToRange([type] value, [type] min, [type] max)` methods which constrain the given value to the closed range defined by the `min` and `max` values. They return the value itself if it’s within the range, the `min` if it’s below the range and the `max` if it’s above the range.

### common.util.concurrent

- `ForwardingBlockingDeque`: added; moved from `common.collect` because `BlockingDeque` is a concurrent type rather than a standard collection (it’s defined in `java.util.concurrent`).
- `AtomicLongMap`: added a number of methods such as `accumulateAndGet(K, LongBinaryOperator)` that take advantage of new Java functional types.
- `Monitor`: added `newGuard(BooleanSupplier)`.
- `MoreExecutors`: removed `sameThreadExecutor()`; deprecated since 18.0 in favor of `directExecutor()` (preferable) or `newDirectExecutorService()`.

Kategorien: [Allgemein](https://tutego.de/blog/javainsel/category/allgemein/), [Guava/Google Core Libraries](https://tutego.de/blog/javainsel/category/guava-google-core-libraries/), [Open Source](https://tutego.de/blog/javainsel/category/open-source/)

[← Alle Beiträge](https://tutego.de/blog/javainsel/)

---

## Navigation

- Next: [Die Klassen OutputStream und InputStream](https://tutego.de/blog/javainsel/2017/02/die-klassen-outputstream-und-inputstream.md)
