commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paul Benedict (JIRA)" <j...@apache.org>
Subject [jira] Commented: (LANG-642) Need varargs form of NumberUtils.max(), etc
Date Wed, 25 Aug 2010 20:13:17 GMT

    [ https://issues.apache.org/jira/browse/LANG-642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12902610#action_12902610
] 

Paul Benedict commented on LANG-642:
------------------------------------

Adding additional overloads is only necessary when a common use case supports it. Everytime
varargs is used, Java boxes the arguments in an Object[]. This instantiation can be costly
if someone is doing 4 arguments over and over. However, there are workaround such as pooling.


Based on the advice of Effective Java, the recommended solution is to provide explicit types
for the most common cases, and then make one end in varargs. Example:
int max(int n1, int n2);
int max(int n1, int n2, int n3);
int max(int n1, int n2, int n3, int... others);

I recommend we take this approach.

> Need varargs form of NumberUtils.max(), etc
> -------------------------------------------
>
>                 Key: LANG-642
>                 URL: https://issues.apache.org/jira/browse/LANG-642
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.math.*
>            Reporter: david cogen
>            Priority: Minor
>
> There should be a varargs form of the NumberUtils.max() and min() functions.
> E.g. int max (int... numbers)
> This might conflict with the existing int max (int[] numbers) but that function would
in fact not be needed if the varargs form existed because an array could be supplied to it
just as easily.
> Or, if it is undesirable to remove max(int[] numbers), then a varargs function could
be defined as
> int max (int number1, int... moreNumbers)
> which would work for any number of arguments greater than 0.
> Of course this function should be implemented for all number types (byte, short, float,
double, etc) and both max() and min() should be provided.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message