为什么我不能指定'长'值40亿? [英] Why can't I assign a 'long' a value of 4 billion?

查看:136
本文介绍了为什么我不能指定'长'值40亿?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Java中声明一个long值,但遗憾的是它不起作用。

I'm trying to declare a long value in Java, which unfortunately does not work.

这是我的代码。它会导致以下错误消息:int类型的文字4294967296超出范围。

This is my code. It results in the following error message: "The literal 4294967296 of type int is out of range".

long bytes = 4294967296;

我需要这个值来制作一个文件过滤器来筛选出大于4294967296字节的文件(4GB) )。相反的方式没有任何问题( long size = file.length())与每个文件大小,这就是为什么我无法弄清楚为什么我的声明不是工作。

I need this value to make a file filter that filters out files that are bigger than 4294967296 bytes (4GB). The other way round works without any issues (long size = file.length()) with every file size, which is why I can't figure out why my declaration is not working.

推荐答案

L 添加到数字的末尾:

long bytes = 4294967296L;

这篇关于为什么我不能指定'长'值40亿?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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