I am just wondering if anyone is aware of the rationale behind this particular item in the standard Java coding conventions. The Java coding conventions say to put a space after a cast, like this:
Object myObj = (Object) someThing;
^
It's the same syntax as casts in C, which never have a space after them:
Object myObj = (Object)someThing;
^
I thought that this was because the cast is a unary operator. Putting a space there would be like doing this:
int x = ++ y;
while (0 < ++ x) { ... }
...which is not something you usually see:
int x = ++y;
while (0 < ++x) { ... }
This seems to be unique to Java, so if anyone has any insight, I'd love to hear it.
Well in Java Language Specification "Expressions" cast expressions do not belong to "15.15 Unary Operators", but have an own subtitle "15.16 Cast Expressions". It is primarly not refered to as cast operator, but cast expression and the spec says that "the parentheses and the type they contain are sometimes called the cast operator."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With