RFR: JDK-8348030 : Extend Math.min and Math.max to support multiple parameters [v2]
Aviad Zer
duke at openjdk.org
Mon Jan 20 12:02:37 UTC 2025
On Mon, 20 Jan 2025 11:48:20 GMT, Martin Desruisseaux <duke at openjdk.org> wrote:
>> Aviad Zer has updated the pull request incrementally with one additional commit since the last revision:
>>
>> Update Math.java by adding extended max function
>
> Aren't `Math.min(values)` methods duplicating `Arrays.stream(values).min()`? Except for the `float` type, for which there is no stream.
Thank you for your feedback @desruisseaux !
While Arrays.stream(values).min() can indeed be used for int, long, and double, I believe that Math.min(values...) provides a more concise and intuitive alternative for these cases. Developers might prefer the simplicity of using a single method, especially when working with smaller sets of values where creating a stream might feel excessive.
As you pointed out, the Streams API does not support float arrays directly. The Math.min(float...) method addresses this gap, offering a consistent API for all primitive types.
Including varargs-based Math.min methods for all primitive types ensures consistency across the Math class and improves code readability.
I hope this clarifies the motivation behind the proposal. Please let me know if you have further suggestions or feedback!
-------------
PR Comment: https://git.openjdk.org/jdk/pull/23138#issuecomment-2602234412
More information about the core-libs-dev
mailing list