【问题标题】:Cannot compile due has private access and error happens only in IntelliJ Idea based IDE由于具有私有访问权限而无法编译,并且错误仅在基于 IntelliJ Idea 的 IDE 中发生
【发布时间】:2013-12-20 01:34:17
【问题描述】:

我在一周前尝试使用带有 android SDK 的 IntellJ IDEA,今天我尝试编译一个新项目,但出现此错误

java: java.util.LinkedHashMap.Entry has private access in java.util.LinkedHashMap

相关

private final HashMap<String, Bitmap> sHardBitmapCache = new LinkedHashMap<String, Bitmap>(HARD_CACHE_CAPACITY / 2,
        0.75f, true) {
    @Override
    protected boolean removeEldestEntry(LinkedHashMap.Entry<String, Bitmap> eldest) {
        if (size() > HARD_CACHE_CAPACITY) {
            sSoftBitmapCache.put(eldest.getKey(), new SoftReference<Bitmap>(eldest.getValue()));
            return true;
        } else
            return false;
    }
};

【问题讨论】:

  • 如果使用接口怎么办:Map.Entry&lt;String, Bitmap&gt; eldest

标签: java android intellij-idea android-studio


【解决方案1】:

在你的方法中使用Map接口代替:

private final Map<String, Bitmap> sHardBitmapCache = new LinkedHashMap<String, Bitmap>(HARD_CACHE_CAPACITY / 2,
        0.75f, true) {

    @Override
    protected boolean removeEldestEntry(Map.Entry<String, Bitmap> eldest) {
        if (size() > HARD_CACHE_CAPACITY) {
            sSoftBitmapCache.put(eldest.getKey(), new SoftReference<Bitmap>(eldest.getValue()));
            return true;
        } else
            return false;
    }
};

这是Map 上的公共嵌套接口,如下所示:

java.util.Map Source Code

您会注意到LinkedHashMap 中的嵌套静态类是私有的,如下所示:

java.util.LinkedHashMap Source Code

【讨论】:

  • 但是在 Eclipse 中这个编译没有问题并且运行没有错误或崩溃。为什么?
  • 两个 IDE 都使用同一个 jdk 吗?当我导入您的代码时,Eclipse 给了我一个错误。
  • @AndreaF 很高兴你找到它!
猜你喜欢
  • 2020-05-07
  • 2011-12-22
  • 1970-01-01
  • 1970-01-01
  • 2023-03-10
  • 1970-01-01
  • 2021-02-28
  • 1970-01-01
  • 2023-03-10
相关资源
最近更新 更多