java中强制转换的优先级是什么? [英] What is the priority of casting in java?
本文介绍了java中强制转换的优先级是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有一行类似于
int s = (double) t/2
和
int s = (double) (t/2)
或
int s = ((double) t)/2
?
推荐答案
这应该会让事情更清楚一些. 简而言之,强制转换优先于除法运算,因此它与给出的输出相同
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;
正如 knoight 所指出的,这在技术上与没有括号的操作不同,因为它们也有优先级.但是,就本示例而言,它将提供相同的结果,并且在所有意图和目的上都是等效的.
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.
这篇关于java中强制转换的优先级是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文