问题描述
这是我的一个例子.
public int getDelta()
{
long time = getTime();
int delta = (int) (time - lastFrame);
lastFrame = time;
return delta;
}
在第四行中有一个(int)".是什么意思?
In the fourth line, there's an "(int)". What does it mean?
这段代码只是我发现的一个例子;我不是在寻找对我发布的代码的特定答案.通常,(int)甚至会做什么.我也看到它用(字节)完成了.
This code is just an example I found with it; I'm not looking for a specific answer to the code I posted. What the (int) even does, generally. I've seen it done with (byte) too.
推荐答案
这意味着您正在将long转换为int.请参阅: http://en.wikipedia.org/wiki/Type_conversion
It means you're casting a long into an int. See: http://en.wikipedia.org/wiki/Type_conversion
你不能只是说
int delta = (time - lastFrame);
因为时间和lastFrame很长(我假设lastFrame至少是).因此,您必须将减法的结果类型(转换)转换为整数值.
Because time and lastFrame are longs (I'm assuming lastFrame is, at least). Therefore you must convert the type (cast) the result of that subtraction into an integer value.
这篇关于给整数赋值时,括号中的“整数"是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!