简体   繁体   English

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

[英]ArrayList creation: (some object) cannot be stored in an array of type java.lang.Object[]

Usually, the code block works perfect. 通常,代码块工作得很完美。 On very rare occasions though, the "new ArrayList" throws an Exeption my.namespace.CacheEntry cannot be stored in an array of type java.lang.Object[] . 但是在极少数情况下,“new ArrayList”会抛出一个Exeption my.namespace.CacheEntry,不能存储在java.lang.Object []类型的数组中

Checking Google, someone else seemed to get this exception on an Acer A500 with 3.1 (which is the device I got it, too). 检查谷歌,其他人似乎在带有3.1的Acer A500上获得了这个例外(这也是我得到它的设备)。 I don't see any hit for this in generic Java or whatever, so may be some very very Honeycomb special case or even a VM bug? 我在通用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);

The CacheEntry class is quite regular, too: 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);
        }
     }

I don't see anything wrong with this code. 我没有看到这段代码有什么问题。 Anyone? 任何人?

may be some very very Honeycomb special case or even a VM bug? 可能是一些非常非常蜂窝的特殊情况甚至VM漏洞?

Yes, looks like it, because according to Java semantics, there isn't anything that "cannot be stored in an array of type java.lang.Object[]" - except primitives, but those can't be values in a HashMap 是的,看起来像它,因为根据Java语义, 没有任何“不能存储在类型java.lang.Object []”的数组中 - 除了原语,但那些不能是HashMap

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.util.arraylist 不能转换为 java.lang.object[] - java.util.arraylist cannot be cast to java.lang.object[] 从Object数组到Object不能转换为java.lang.Object - From Object array to Object cannot be cast to java.lang.Object Xamarin Java.Lang.Object创建效率低下 - Xamarin Java.Lang.Object creation is inefficient 如何将 java.lang.Object 转换为 ArrayList? - How to convert java.lang.Object to ArrayList? Java类型不匹配:无法从java.lang.Object转换 - Java Type mismatch: cannot convert from java.lang.Object 无法解析java.lang.object类型 - Eclipse buildpath无法正常工作 - The type java.lang.object cannot be resolved - Eclipse buildpath not working Eclipse 消息(无法解析类型 java.lang.Object) - Eclipse message (The type java.lang.Object cannot be resolved) org.springframework.data.mapping.MappingException:无法将类型类 java.util.ArrayList 转换为类 java.lang.Object 的实例 - org.springframework.data.mapping.MappingException: Cannot convert type class java.util.ArrayList into an instance of class java.lang.Object java.lang.ClassCastException: java.util.ArrayList 不能转换为 java.lang.Object[] - java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.lang.Object[] 无法反序列化 `java.util.ArrayList 的实例<java.lang.object> ` 超出 START_OBJECT 令牌</java.lang.object> - Cannot deserialize instance of `java.util.ArrayList<java.lang.Object>` out of START_OBJECT token
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM