2 ms·
> Additionally although not relevant to the code in question, the author's habit of using if/else vs. ternary (or if-only) can have performance and caching impl
by vardump 12y ago
> Additionally although not relevant to the code in question, the author's habit of using if/else vs. ternary (or if-only) can have performance and caching implications:
If ternary and if-else statement don't perform same in both cases, I'd call it a bug in JVM. On C/C++ compilers I've tried, ternary has always compiled to exactly same as if-else-statement.
- logn 12y agoThe Java code ends up being different in subtle ways. Exemplified by this: static int x[] = new int[1]; public static void main1(String[] args) { x[1] = grow() ? 10 : 20; //array index out of bounds! } public static void main2(String[] args) { if (grow()) { x[1] = 10; } else { x[1] = 20; } //no exceptions thrown } private static boolean grow() { x = new int[2]; return true; }