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

James Sawle commented on LANG-1050:
-----------------------------------

Whilst I agree that {noformat}Long[] array = ArrayUtils.nullToEmpty(someArray, 
Long.class){noformat} may not be the nicest syntax when dealing with Strings, 
Longs etc, the current implementation makes it very difficult to work with 
other classes. Maybe a method that takes the type could be generated and the 
other methods modified to use it?

Also the other methods should be using ArrayUtils.isEmpty instead of carrying 
out the implementation time. However, if not using shared instances (could 
dynamically build a map at Runtime to optimize performance), a null check would 
suffice.

[~joehni] Using the toArray method like this will throw a ClassCastException, 
attempting to convert an empty array of Object to the desired type.

> 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)

Reply via email to