It is a known fact, that in Java it is good practice to return Collections.emptyList instead of empty ArrayList object. When writing for GWT, how does GWT compiler treat this emptyLis开发者_开发技巧t - is it as efficient to use as ArrayList or it doesn't make any sense?
Collections.emptyList()
might be better than new ArrayList()
(compare this to that), but I believe it actually doesn't matter (ArrayList
is probably used anyway –it's used internally in widgets–, so it won't be optimized out if you use Collections.emptyList()
, and the EmptyList
is so small that it's not worth optimizing it out; and again it might also be used somewhere by code you didn't write, so…).
As a rule of thumb, you shouldn't care for micro-optimizations unless you have a performance/code-size issue that needs fixing. “Premature optimization is the root of all evil.” (Donald Knuth)
精彩评论