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
Post a Comment