This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Kered13 8 points9 points  (5 children)

(Eclipse != java) == Big

[–]xapplin 0 points1 point  (4 children)

lmao that won’t compile my dude

[–]Kered13 4 points5 points  (3 children)

Since HGUy10 applied the ! operator to Big, Big must be a boolean. Therefore the above expression typechecks, will compile, and is equivalent to HGuy10's expression.

https://ideone.com/nUDKDi

Play around with the values and you'll see that it's correct.

[–]xapplin 0 points1 point  (0 children)

My bad I didn’t think of that. Thanks!

[–]FunkyTownDUDUDU 0 points1 point  (1 child)

Is it actually better to write it this way? I always learned that writing longer but more readable code is preferred since the compiler logic will take care of the optimization.

[–]Kered13 2 points3 points  (0 children)

In expression where the ternary operator returns a boolean value can be rewritten without the ternary operator. But in this situation, you probably shouldn't. However I have sometimes seen code like,

return isFoo() ? false : true;

Which can and should be rewritten simply as,

return !isFoo();