【问题标题】:Strange @hide behavior [duplicate]奇怪的@hide行为[重复]
【发布时间】:2014-03-21 13:04:47
【问题描述】:

BitmapFactory.decodeStream方法中:

public static Bitmap decodeStream(InputStream is, Rect outPadding, Options opts) {
        // we don't throw in this case, thus allowing the caller to only check
        // the cache, and not force the image to be decoded.
        if (is == null) {
            return null;
        }

        Bitmap bm = null;

        Trace.traceBegin(Trace.TRACE_TAG_GRAPHICS, "decodeBitmap");
        try {
            if (is instanceof AssetManager.AssetInputStream) {
                final int asset = ((AssetManager.AssetInputStream) is).getAssetInt();
                bm = nativeDecodeAsset(asset, outPadding, opts);
            } else {
                bm = decodeStreamInternal(is, outPadding, opts);
            }

            if (bm == null && opts != null && opts.inBitmap != null) {
                throw new IllegalArgumentException("Problem decoding into existing bitmap");
            }

            setDensityFromOptions(bm, opts);
        } finally {
            Trace.traceEnd(Trace.TRACE_TAG_GRAPHICS);  // THAT IS COLLISION LINE
        }

        return bm;
    }

我们看到Trace.TRACE_TAG_GRAPHICS 的用法。好的,我们来看看Trace.java

public final class Trace {
    /*
     * Writes trace events to the kernel trace buffer.  These trace events can be
     * collected using the "atrace" program for offline analysis.
     */

    private static final String TAG = "Trace";

    // These tags must be kept in sync with system/core/include/cutils/trace.h.
    /** @hide */
    public static final long TRACE_TAG_NEVER = 0;
    /** @hide */
    public static final long TRACE_TAG_ALWAYS = 1L << 0;
    /** @hide */
    public static final long TRACE_TAG_GRAPHICS = 1L << 1;
    ...

当我尝试使用Trace.TRACE_TAG_GRAPHICS 标志编译器给我错误,这个标签不对我负责。我同意他的看法。

但问题是 - 为什么 BitmapFactory 可以访问 @hide 变量,而为什么我不能?

【问题讨论】:

  • 这就是@hide 所做的。它可以防止第三方开发人员访问框架中的内容。
  • 我不同意你的观点。看code.google.com/p/doclava/wiki/JavadocTags#@hide
  • 因为编译了常规和未隐藏的 android 版本,我可以告诉你一个事实,@hide 的东西不包含在已发布的 API 中。 (您可以自己看到,因为您可以看到您无法针对它们进行编译)
  • 这是一个不重复的问题......
  • 我认为,重复问题的答案确实回答了您的问题。

标签: java android


【解决方案1】:

对于不属于已发布的官方 Android API 的 私有 API,Android 使用 @hide 注释来防止它们被包含在编译程序的 jar 中。无法保证这些将来会可用,因此您不应依赖它们。如需使用,可通过Reflection访问。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-06-28
    • 2015-07-26
    • 2020-04-26
    • 2015-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多