Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java coding conventions: what is the rationale for a space after a cast?

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.

like image 274
Droj Avatar asked Jul 01 '15 18:07

Droj


1 Answers

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."

like image 124
user140547 Avatar answered Oct 06 '22 19:10

user140547