-2
在Collections.unmodifiableList實現我發現它總是用UnmodifiableList包裝給定的列表,即使給定的列表已經是UnmodifiableList ...所以如果我反覆調用這個方法 - 我得到一個巨大的堆棧跟蹤,像這樣:Collections.unmodifiableList包裝已經不可修改的列表?
at java.util.Collections$UnmodifiableCollection.size(Collections.java:998)
at java.util.Collections$UnmodifiableCollection.size(Collections.java:998)
at java.util.Collections$UnmodifiableCollection.size(Collections.java:998)
at java.util.Collections$UnmodifiableCollection.size(Collections.java:998)
at java.util.Collections$UnmodifiableCollection.size(Collections.java:998)
at java.util.Collections$UnmodifiableCollection.size(Collections.java:998)
at java.util.Collections$UnmodifiableCollection.size(Collections.java:998)
at java.util.Collections$UnmodifiableCollection.size(Collections.java:998)
at java.util.Collections$UnmodifiableCollection.size(Collections.java:998)
at java.util.Collections$UnmodifiableCollection.size(Collections.java:998)
at java.util.Collections$UnmodifiableCollection.size(Collections.java:998)
at java.util.Collections$UnmodifiableCollection.size(Collections.java:998)
at java.util.Collections$UnmodifiableCollection.size(Collections.java:998)
at java.util.Collections$UnmodifiableCollection.size(Collections.java:998)
at java.util.Collections$UnmodifiableCollection.size(Collections.java:998)
at java.util.Collections$UnmodifiableCollection.size(Collections.java:998)
at java.util.Collections$UnmodifiableCollection.size(Collections.java:998)
at java.util.Collections$UnmodifiableCollection.size(Collections.java:998)
at java.util.Collections$UnmodifiableCollection.size(Collections.java:998)
at java.util.Collections$UnmodifiableCollection.size(Collections.java:998)
at java.util.Collections$UnmodifiableCollection.size(Collections.java:998)
at java.util.Collections$UnmodifiableCollection.size(Collections.java:998)
at java.util.Collections$UnmodifiableCollection.size(Collections.java:998)
我認爲檢查列表已經UnmodifiabelList,就回到同一個列表,像谷歌的藏品做,但這不是一個公共類..
任何suggeestions如何優雅地解決這個問題?
感謝
你能告訴我們如何產生的行爲呢? – 2013-05-09 16:49:53
使用上述Google集合? ;) – 2013-05-09 16:51:13
爲什麼你一次又一次調用這個方法? – 2013-05-09 16:52:23