public static boolean arrayNullOrEmpty(byte[] objs)
{
return objs == null || objs.length == 0;
}
now want to use generics, is this method can be int [], double [] a general purpose , how to write
------ Solution ---------- ----------------------------------
overload
------ Solution - ------------------------------------------
public static <T> boolean arrayNullOrEmpty(T[] array) {
return array == null || array.length == 0;
}
public static boolean arrayNullOrEmpty(Object array) {
if (array == null) {
return true;
}
if (!array.getClass().isArray()) {
throw new IllegalArgumentException("{" + array + "} is not an array!");
}
return Array.getLength(array) == 0;
}
------ Solution ------------------------------------------ -
above that can deal with an array of objects , the following take-
------ For reference only ---------------------- -----------------
thxxxxxxxxxxxx
没有评论:
发表评论