开发者

How to encapsulate an ArrayList in Java

I am开发者_开发问答 trying to write a getter for an ArrayList in Java such that the list returned cannot be modified (ideally at compile time). I know there must be some simple way to do this but it is eluding me. Does anybody know how to do this?


Collections.unmodifiableList(...) is simple solution. Better one would be to use ImmutableList from google-guava library


You can use the Collections.unmodifiableList. As short example is available here.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜