Github user sebbASF commented on a diff in the pull request:
https://github.com/apache/commons-lang/pull/336#discussion_r200857303
--- Diff: src/main/java/org/apache/commons/lang3/ArrayUtils.java ---
@@ -8672,4 +8672,53 @@ public static void shuffle(final double[] array,
final Random random) {
swap(array, i - 1, random.nextInt(i), 1);
}
}
+
+ /**
+ * Gets an element from the array if the array is non-null and
appropriately long, otherwise returns null
+ * @param <T> the component type of the array
+ * @param array the array holding the desired element
+ * @param index the index of the element in the array
+ * @return The element in the array at the index, or null if it is
ill-formatted
+ * @since 3.8
+ */
+ public static <T> T get(T[] array, int index){
+ return get(array, index, null);
+ }
+
+ /**
+ * Gets an element from the array if the array is non-null and
appropriately long, otherwise returns the specified value
+ * @param <T> the component type of the array
+ * @param array the array holding the desired element
+ * @param index the index of the element in the array
+ * @param defaultReturn the object to be returned if the array is null
or shorter than the index
+ * @return The element in the array at the specified index, or the
given argument if it is ill-formatted
--- End diff --
ill-formatted?
Again, I don't see the point of this method.
It's a bit more flexible than the original method.
But it's still only useful for the case where you can choose a default
value that does not appear in the array, and you still have to check whether
the return value is the default or not.
---