开发者

Any difference in GWT between Collections.emptyList() and new ArrayList()

开发者 https://www.devze.com 2023-03-14 05:04 出处:网络
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

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)

0

精彩评论

暂无评论...
验证码 换一张
取 消