You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "James Sawle (JIRA)" <ji...@apache.org> on 2014/10/15 23:24:40 UTC

[jira] [Comment Edited] (LANG-1050) Change nullToEmpty methods to generics

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

James Sawle edited comment on LANG-1050 at 10/15/14 9:24 PM:
-------------------------------------------------------------

My suggestion was the following.

{code}
public static <T> T[] nullToEmpty(final T[] array) {
    if (isEmpty(array)) {
        return toArray();
    }
    return array;
}
{code}

An empty array will be generated by the JVM to handle the varargs parameter, giving the desired behaviour.


was (Author: jamessawle):
My suggestion was the following.

{code}
public static T[] nullToEmpty(final T[] array) {
    if (isEmpty(array)) {
        return toArray();
    }
    return array;
}
{code}

An empty array will be generated by the JVM to handle the varargs parameter, giving the desired behaviour.

> Change nullToEmpty methods to generics
> --------------------------------------
>
>                 Key: LANG-1050
>                 URL: https://issues.apache.org/jira/browse/LANG-1050
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.*
>            Reporter: James Sawle
>
> Currently there are multiple Object based methods which could be replaced by a single generic method.
> - public static Long[] nullToEmpty(final Long[] array)
> - public static Integer[] nullToEmpty(final Integer[] array)
> - public static Short[] nullToEmpty(final Short[] array)
> - public static Character[] nullToEmpty(final Character[] array)
> - public static Byte[] nullToEmpty(final Byte[] array)
> - public static Double[] nullToEmpty(final Double[] array)
> - public static Float[] nullToEmpty(final Float[] array)
> - public static Boolean[] nullToEmpty(final Boolean[] array)
> Recommendation, replace all of these with a single method that would also allow a defensive programming style when not using wrapped primitives.
> - public static <T> T[] nullToEmpty(final T[] array)



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)