tag:blogger.com,1999:blog-441421458098194397.post985545082118798732..comments2024-03-15T12:32:02.846+02:00Comments on May the source be with you!: Using of Collections.emptyList() the right way in Java 1.5+jNaydenhttp://www.blogger.com/profile/04678280364638370213noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-441421458098194397.post-76842249287185796732015-09-07T20:42:43.431+03:002015-09-07T20:42:43.431+03:00"passing emptyList to a class that has a publ..."passing emptyList to a class that has a public getter that exposes List is a bad practice"<br /><br />i have to correct this nonsense. implementations of List are not required to support adding elements, so clients should always be aware that the add method may throw. emptyList() is no worse than unmodifiableList().Sir Moonhttps://www.blogger.com/profile/12070553552963650848noreply@blogger.comtag:blogger.com,1999:blog-441421458098194397.post-20193632080002152392010-07-28T11:14:28.140+03:002010-07-28T11:14:28.140+03:00Stilgar : Agree I was needing only the seter for t...Stilgar : Agree I was needing only the seter for that example, I agree about the getter. :) Shame on eclipse it generates everything :DD kidding :DjNaydenhttps://www.blogger.com/profile/04678280364638370213noreply@blogger.comtag:blogger.com,1999:blog-441421458098194397.post-71514373294784420732010-07-28T11:08:49.916+03:002010-07-28T11:08:49.916+03:00Didn't know that. Thanks for posting it.Didn't know that. Thanks for posting it.Unknownhttps://www.blogger.com/profile/14547683712276442702noreply@blogger.comtag:blogger.com,1999:blog-441421458098194397.post-31195006834240169532010-07-28T11:05:19.229+03:002010-07-28T11:05:19.229+03:00I am aware that the article deals with the languag...I am aware that the article deals with the language syntax but I must point out that passing emptyList to a class that has a public getter that exposes List is a bad practice. The consumer does not know that the implementation is an emptyList and will throw an exception when the add method is called. This makes using emptyList inappropriate. The example would be OK if instead of List the Book class exposed IterableStilgarhttps://www.blogger.com/profile/12728026428525633767noreply@blogger.comtag:blogger.com,1999:blog-441421458098194397.post-81514379259082864902010-07-28T10:47:52.086+03:002010-07-28T10:47:52.086+03:00Wow, strange but neat! I didn't know this at a...Wow, strange but neat! I didn't know this at all and always used the method proposed in answer 4.Unknownhttps://www.blogger.com/profile/15922821736780985548noreply@blogger.comtag:blogger.com,1999:blog-441421458098194397.post-74037843182152854242010-07-28T10:22:22.580+03:002010-07-28T10:22:22.580+03:00Very strange indeed :)Very strange indeed :)jNaydenhttps://www.blogger.com/profile/04678280364638370213noreply@blogger.comtag:blogger.com,1999:blog-441421458098194397.post-923242620649067482010-07-28T07:32:16.785+03:002010-07-28T07:32:16.785+03:00That was very new for me and of course very strang...That was very new for me and of course very strange. Thanks it was very clear.Anonymoushttps://www.blogger.com/profile/07260242968912080027noreply@blogger.com