java - Returning an empty array -


question

this may silly question, there difference between foo() , bar()?


code

private static file[] foo() {     return collections.emptylist().toarray(new file[0]); } 

private static file[] bar() {     return new file[0]; } 

i'm trying think of best way return empty array, rather null.

a different way return empty array use constant empty arrays of given type same.

private static final file[] no_files = {}; private static file[] bar(){     return no_files; } 

Comments

Popular posts from this blog

python - Why doesn't list have safe "get" method like dictionary? -

razor - Is this a bug in WebMatrix PageData? -

sql server - Stored procedure -