繁体   English   中英

ArrayList创建:(某个对象)不能存储在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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM