![](/img/trans.png)
[英]java.util.arraylist cannot be cast to java.lang.object[]
[英]ArrayList creation: (some object) cannot be stored in an array of type java.lang.Object[]
通常,代碼塊工作得很完美。 但是在極少數情況下,“new ArrayList”會拋出一個Exeption my.namespace.CacheEntry,不能存儲在java.lang.Object []類型的數組中 。
檢查谷歌,其他人似乎在帶有3.1的Acer A500上獲得了這個例外(這也是我得到它的設備)。 我在通用Java或其他任何東西中都沒有看到任何打擊,所以可能是一些非常非常的Honeycomb特殊情況甚至VM錯誤?
private long expireCache(HashMap<String, CacheEntry> map) {
long count = 0;
// next line will sometimes throw the exception:
ArrayList<CacheEntry> entries = new ArrayList<CacheEntry>(map.values());
Collections.sort(entries);
CacheEntry類也非常規則:
final class CacheEntry implements Comparable<CacheEntry> {
public File file;
public Long time;
CacheEntry(File cacheFile) {
// retreive the lastModified only once, don't do heavy I/O for sorting,
// keep it desynced from filesystem so nothing bad happens when the
// file gets changed while sorting:
file = cacheFile;
time = cacheFile.lastModified();
}
// "touch" the cached last modified time
public void touch() {
time = System.currentTimeMillis();
}
// return the long comparable of last modified time
public int compareTo(CacheEntry c) {
return time.compareTo(c.time);
}
}
我沒有看到這段代碼有什么問題。 任何人?
可能是一些非常非常蜂窩的特殊情況甚至VM漏洞?
是的,看起來像它,因為根據Java語義, 沒有任何“不能存儲在類型java.lang.Object []”的數組中 - 除了原語,但那些不能是HashMap
值
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.