The note that I'd like to summarize here is about the method design in Java language and more particularly about the return value when they are either Array type or Collection objects.
It's sometimes argued that a null return value is preferable to an empty array because it avoids the expense of allocating the array.This argument fails on 2 counts.It's possible to return the same zero-length array from every invocation that returns no items because zero-length arrays are immutable and immutable objects may be shared freely.
For collection, use the following appropriately.
Collections.emptySet();Collections.emptyList();Collections.emptyMap();
for array, use the following technique.
(the following example is the case the array type is String)
private static final String[] EMPTY_STRING_ARRAY = new String[0];Collections.toArray(EMPTY_STRING_ARRAY);

No comments:
Post a Comment