java存储对象的数组_ArrayList创建:(某个对象)不能存储在java.lang.Object []类型的数组中...

通常情况下,代码块是完美的。但在非常罕见的情况下,“新ArrayList”会抛出一个Exeption my.namespace.CacheEntry不能存储在类型为java.lang.Object []的数组中。

检查谷歌,别人似乎得到这个例外与宏基A500 3.1(这也是我得到的设备)。在泛型Java或其他类似的东西中,我没有看到任何这样的命中,所以可能会有一些非常非常非常蜂巢式的特殊情况,甚至是虚拟机bug。

private long expireCache(HashMap map) {

long count = 0;

// next line will sometimes throw the exception:

ArrayList entries = new ArrayList(map.values());

Collections.sort(entries);CacheEntry类也很常见:

final class CacheEntry implements Comparable {

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);

}

}我没有看到这个代码有什么问题。任何人?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值