' int'是什么?括号中的意思是给int赋值? [英] What does a 'int' in parenthesis mean when giving a value to an int?

查看:62
本文介绍了' int'是什么?括号中的意思是给int赋值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的一个例子.

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.

这篇关于' int'是什么?括号中的意思是给int赋值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆