[BUG] Fix allMin/allMax test compilation errors with Comparator.naturalOrder()#108
Open
akgitrepos wants to merge 1 commit intogoogle:masterfrom
Open
[BUG] Fix allMin/allMax test compilation errors with Comparator.naturalOrder()#108akgitrepos wants to merge 1 commit intogoogle:masterfrom
akgitrepos wants to merge 1 commit intogoogle:masterfrom
Conversation
- Changed downstream collector type from Collector<? super T, ?, R> to Collector<T, ?, R> to improve type inference with Comparator.naturalOrder() - Added explicit type witnesses in tests: Comparator.<Integer>naturalOrder() and onlyElement(identity()) to help Java's type inference This fixes 6 test compilation errors: - testAllMax_empty - testAllMax_toOnlyElement - testAllMax_multiple - testAllMin_empty - testAllMin_toOnlyElement - testAllMin_multiple
Author
|
@fluentfuture Hi, I have fixed test compilation issues on MoreCollectorsTest.java. Would appreciate a review. Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes 6 test compilation errors in
MoreCollectorsTest.javathat prevent tests from compiling when usingComparator.naturalOrder()with theallMin/allMaxcollector methods.Problem
Tests like
testAllMax_empty,testAllMax_toOnlyElement, etc. fail with:Java's type inference fails when combining:
Comparator.naturalOrder()- returnsComparator<Comparable<? super T>>toImmutableList()- returnsCollector<Object, ?, ImmutableList<Object>>The wildcards
? super Tin the method signature prevent Java from correctly inferringT.Solution
1. Method signature change (
MoreCollectors.java)Changed downstream collector type from
Collector<? super T, ?, R>toCollector<T, ?, R>:2. Test fixes (
MoreCollectorsTest.java)Added explicit type witnesses to ensure robust type inference:
Comparator.<Integer>naturalOrder()onlyElement(identity())Files Changed
mug/src/main/java/com/google/mu/util/stream/MoreCollectors.java(2 lines)mug/src/test/java/com/google/mu/util/stream/MoreCollectorsTest.java(2 lines)Testing