What is the priority of casting in java?

自作多情 提交于 2019-12-17 15:56:38

问题


if I have a line of code that goes something like

int s = (double) t/2   

Is it the same as

int s = (double) (t/2)

or

int s = ((double) t)/2

?


回答1:


This should make things a bit clearer. Simply put, a cast takes precedence over a division operation, so it would be the same thing as give the same output as

int s = ((double)t) / 2;

Edit: As knoight has pointed out, this is not technically the same operation as it would be without the parentheses, since they have a priority as well. However, for the purposes of this example, it will offer the same result, and is for all intents and purposes equivalent.



来源:https://stackoverflow.com/questions/23464036/what-is-the-priority-of-casting-in-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!