glaz666
glaz666

Reputation: 8731

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

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 emptyList - is it as efficient to use as ArrayList or it doesn't make any sense?

Upvotes: 4

Views: 408

Answers (1)

Thomas Broyer
Thomas Broyer

Reputation: 64541

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)

Upvotes: 5

Related Questions