How to return a thread safe/immutable Collection in Java?
问题 In the project I am coding, I need to return a thread safe and immutable view from a function. However, I am unsure of this. Since synchronizedList and unmodifiableList just return views of a list, I don't know if Collections.synchronizedList(Collections.unmodifiableList(this.data)); would do the trick. Could anyone tell me if this is correct, and in case it is not, are there any situations that this would likely to fail? Thanks for any inputs! 回答1: I find this to be a real gap in the JDK.