android renderscript 源中可能有一个小错误

发布于 2024-10-16 19:58:29 字数 438 浏览 8 评论 0原文

只是浏览 渲染脚本源。 我想我在第 36 行发现了一个错误

private static final boolean LOG_ENABLED = DEBUG ? Config.LOGD : Config.LOGV;

Think that need to be a double == 但没有足够的编码经验来确定。

just looking through the source for renderscript.
I think I spotted a mistake, on line 36

private static final boolean LOG_ENABLED = DEBUG ? Config.LOGD : Config.LOGV;

Think that needs to be a double == but don't have enough coding experience to be sure.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

过期以后 2024-10-23 19:58:29

不,我不认为这是一个错误。它根据 DEBUG 的值将 LOG_ENABLED 设置为 LOGDLOGV

相关位是:

public class RenderScript {
    static final String LOG_TAG = "libRS_jni";
    private static final boolean DEBUG  = false;
    @SuppressWarnings({"UnusedDeclaration", "deprecation"})
    private static final boolean LOG_ENABLED = DEBUG ? Config.LOGD : Config.LOGV;

最后一行概念上相当于:

    private static final boolean LOG_ENABLED;
    if (DEBUG)
        LOG_ENABLED = Config.LOGD;
    else
        LOG_ENABLED = Config.LOGV;

事实上,

private static final boolean LOG_ENABLED == DEBUG ? Config.LOGD : Config.LOGV;

实际上没有意义,因为它意味着:

private static final boolean ((LOG_ENABLED == DEBUG)
                               ? Config.LOGD
                               : Config.LOGV);

它根本没有声明变量名,只是一个值应该分配给某些东西。

No, I don't think it is a bug. It's setting LOG_ENABLED to either LOGD or LOGV depending on the value of DEBUG.

The relevant bit is:

public class RenderScript {
    static final String LOG_TAG = "libRS_jni";
    private static final boolean DEBUG  = false;
    @SuppressWarnings({"UnusedDeclaration", "deprecation"})
    private static final boolean LOG_ENABLED = DEBUG ? Config.LOGD : Config.LOGV;

and that last line is conceptually equivalent to:

    private static final boolean LOG_ENABLED;
    if (DEBUG)
        LOG_ENABLED = Config.LOGD;
    else
        LOG_ENABLED = Config.LOGV;

In fact,

private static final boolean LOG_ENABLED == DEBUG ? Config.LOGD : Config.LOGV;

doesn't actually make sense since it means:

private static final boolean ((LOG_ENABLED == DEBUG)
                               ? Config.LOGD
                               : Config.LOGV);

which doesn't have a variable name being declared at all, just a value that should be assigned to something.

哑剧 2024-10-23 19:58:29

这只是关于 Java 中的三元运算符如何工作的一个简单的混淆。你正在做类似的事情:

int i;
boolean b;
int n1=2;
int n2=3;

i = b ? n1 : n2;

其中 b 可以是评估 true 或 false 的表达式。我曾经在第一个元素周围使用括号来清楚地表明这一点,尽管我刚刚查看了一些代码,但现在我似乎已经停止这样做了!

It's just a simple bit of confusion about how ternary operators work in Java. You're doing something like:

int i;
boolean b;
int n1=2;
int n2=3;

i = b ? n1 : n2;

where b can be an expression evaluating to true or false. I used to use parenthesis around the first element to make this clear, although I just looked through some of my code and I seem to have stopped doing that now!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文