Dot and new operator precendence in java

36 Views Asked by At

I was looking at Java documentation and this example surprised me:

int height = new Rectangle().height;`

I always thought in such situation you have to use brackets:

int height = (new Rectangle()).height;

because operator precedence table shows that . operator have higher predecence than new operator, if so then why that line of code is executed like this:

int height = (new Rectangle()).height;

instead of being executed like this:

int height = new (Rectangle().height);
0

There are 0 best solutions below