Why do Java and C# not have implicit conversions to boolean?
- by Shaun
Since I started Java it's been very aggravating for me that it doesn't support implicit conversions from numeric types to booleans, so you can't do things like:
if (flags & 0x80) { ... }
instead you have to go through this lunacy:
if ((flags & 0x80) != 0) { ... }
It's the same with null and objects. Every other C-like language I know including JavaScript allows it, so I thought Java was just moronic, but I've just discovered that C# is the same (at least for numbers, don't know about null/objects):
http://msdn.microsoft.com/en-us/library/c8f5xwh7(VS.71).aspx
Microsoft changed it on purpose from C++, so why? Clearly I'm missing something. Why change (what I thought was) the most natural thing in the world to make it longer to type? What on Earth is wrong with it?