-
Notifications
You must be signed in to change notification settings - Fork 24.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Address MinAndMax generics warnings #52642
Conversation
The MinAndMax encapsulates min and max values for a shard. It uses generics to make sure that the values are of the same type and are also comparable. Though there are warnings whenever this class is currently used, which are addressed with this commit. Relates to elastic#49092
Pinging @elastic/es-search (:Search/Search) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some part of the change makes sense to me, like replacing Comparable
with Comparable<T>
but I wonder that some other changes are not needed like replacing T extends Comparable<? super T>
with T extends Comparable<T>
as the former is usually the right way to use generics with wildcards that need to extend Comparable
.
@@ -520,6 +518,14 @@ public static FieldSortBuilder getPrimaryFieldSortOrNull(SearchSourceBuilder sou | |||
return null; | |||
} | |||
|
|||
@SuppressWarnings("unchecked") | |||
private static <T extends Comparable<T>> MinAndMax<T> extractMinAndMax(IndexReader reader, String fieldName, | |||
Function<byte[], Comparable<?>> converter) throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should it be a Function<byte[], ? extends T>
to avoid the unchecked cast?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great point, I missed this
*/ | ||
public class MinAndMax<T extends Comparable<? super T>> implements Writeable { | ||
public class MinAndMax<T extends Comparable<T>> implements Writeable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general this is the right way to use generics with Comparable?
thanks @jpountz for your feedback. When I was working on this change I asked myself even if generics were really useful in this case. I agree with you,
At this point I wonder if all the flexibility given by |
run elasticsearch-ci/2 |
turns out that the compile errors that I was seeing are shown only in IntelliJ. They were weird so it is not surprising that this compiles from command line. I did not understand yet what's causing the error in IntelliJ either, I use the same compiler, and the project itself compiles but when I open I think this is ready then, I went back to |
run elasticsearch-ci/bwc |
Build is green, this should be finally ready ;) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Luca, this LGTM.
`MinAndMax` encapsulates min and max values for a shard. It uses generics to make sure that the values are of the same type and are also comparable. Though there are warnings whenever this class is currently used, which are addressed with this commit. Relates to elastic#49092
thank you very much @jpountz ;) |
`MinAndMax` encapsulates min and max values for a shard. It uses generics to make sure that the values are of the same type and are also comparable. Though there are warnings whenever this class is currently used, which are addressed with this commit. Relates to #49092
The MinAndMax encapsulates min and max values for a shard. It uses generics to make sure that the values are of the same type and are also comparable. Though there are warnings whenever this class is currently used, which are addressed with this commit.
Relates to #49092