Skip to content

Commit

Permalink
Prepare for forthcoming @Nullable annotations on Optional.orElseGet.
Browse files Browse the repository at this point in the history
Soon, nullness checkers will know that `orElseGet` can return `null`... but not be smart enough to know that it can't return `null` _here_.

RELNOTES=n/a
PiperOrigin-RevId: 597579395
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Jan 11, 2024
1 parent cabc183 commit eccc0f6
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions guava/src/com/google/common/collect/Streams.java
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ T get() {
public static OptionalInt findLast(IntStream stream) {
// findLast(Stream) does some allocation, so we might as well box some more
java.util.Optional<Integer> boxedLast = findLast(stream.boxed());
return boxedLast.map(OptionalInt::of).orElseGet(OptionalInt::empty);
return boxedLast.map(OptionalInt::of).orElse(OptionalInt.empty());
}

/**
Expand All @@ -971,7 +971,7 @@ public static OptionalInt findLast(IntStream stream) {
public static OptionalLong findLast(LongStream stream) {
// findLast(Stream) does some allocation, so we might as well box some more
java.util.Optional<Long> boxedLast = findLast(stream.boxed());
return boxedLast.map(OptionalLong::of).orElseGet(OptionalLong::empty);
return boxedLast.map(OptionalLong::of).orElse(OptionalLong.empty());
}

/**
Expand All @@ -989,7 +989,7 @@ public static OptionalLong findLast(LongStream stream) {
public static OptionalDouble findLast(DoubleStream stream) {
// findLast(Stream) does some allocation, so we might as well box some more
java.util.Optional<Double> boxedLast = findLast(stream.boxed());
return boxedLast.map(OptionalDouble::of).orElseGet(OptionalDouble::empty);
return boxedLast.map(OptionalDouble::of).orElse(OptionalDouble.empty());
}

private Streams() {}
Expand Down

0 comments on commit eccc0f6

Please sign in to comment.