You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Mark Dacek (JIRA)" <ji...@apache.org> on 2018/07/07 15:39:00 UTC
[jira] [Updated] (LANG-1402) ArrayUtils should have null and
index-safe get methods.
[ https://issues.apache.org/jira/browse/LANG-1402?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Mark Dacek updated LANG-1402:
-----------------------------
Description:
There should be a safe way to retrieve a value from array without having to check for null and length. It would be a very simple implementation but could save developers a great deal of time in writing and testing.
Something like
{code:java}
String[] a = null;
ArrayUtils.get(a, 5); //returns null
a = new String[5];
ArrayUtils.get(a, 10); // returns null
a[0] = "Hello World";
ArrayUtils.get(a, 0); // returns "Hello World"
{code}
We could handle a few other cases - a default return value. The tricky/annoying thing is the need to cast everything in order to make this
was:
There should be a safe way to retrieve a value from array without having to check for null and length. It would be a very simple implementation but could save developers a great deal of time in writing and testing.
Something like
{code:java}
String[] a = null;
ArrayUtils.get(a, 5); //returns null
a = new String[5];
ArrayUtils.get(a, 10); // returns null
a[0] = "Hello World";
ArrayUtils.get(a, 0); // returns "Hello World"
{code}
> ArrayUtils should have null and index-safe get methods.
> -------------------------------------------------------
>
> Key: LANG-1402
> URL: https://issues.apache.org/jira/browse/LANG-1402
> Project: Commons Lang
> Issue Type: New Feature
> Components: General
> Reporter: Mark Dacek
> Priority: Minor
> Original Estimate: 24h
> Remaining Estimate: 24h
>
> There should be a safe way to retrieve a value from array without having to check for null and length. It would be a very simple implementation but could save developers a great deal of time in writing and testing.
>
> Something like
>
> {code:java}
> String[] a = null;
> ArrayUtils.get(a, 5); //returns null
> a = new String[5];
> ArrayUtils.get(a, 10); // returns null
>
> a[0] = "Hello World";
> ArrayUtils.get(a, 0); // returns "Hello World"
> {code}
>
> We could handle a few other cases - a default return value. The tricky/annoying thing is the need to cast everything in order to make this
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)