I suggested returning Collections.unmodifiableList() instead of directly returning a member variable, and my colleague is concerned that there would be a performance hit. Of course the best answer is to measure it, and we may do that - but I'd like to know your experiences and any references, pro or con.
No. At least, the OpenJDK implementation literally "replaces" the modification methods with UnsupportedOperationException
s, the rest adds one level of indirection, which should just get optimized away by the compiler VM (and even so, one level of indirection wouldn't be costly).
If you wish to return a list that cannot be modified, any performance impact would pale in comparison to the loss in correctness, I wouldn't avoid it for performance alone, and I certainly wouldn't avoid it if it's what you need.