Reputation: 9
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.
Upvotes: 0
Views: 488
Reputation:
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!
Upvotes: 1
Reputation: 881403
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.
Upvotes: 7