当前位置:网站首页>short i =1; I=i+1 and short i=1; Difference of i+=1
short i =1; I=i+1 and short i=1; Difference of i+=1
2022-07-06 19:20:00 【qq_ thirty-seven million seven hundred and five thousand five h】
short i =1; i=i+1 And short i=1; i+=1 The difference between
It's typical to arrive JAVA Basic interview questions , I met in the last interview , Now take a note of .
short i =1; i=i+1;
short i=1;i+=1;
What's the difference between the two ?
When performing arithmetic operations on variables of two data types with different capacities ,java It will automatically improve the accuracy of small volume variables , And then we do the calculation , The result type obtained is the promoted large-capacity data type . If the result is assigned to a variable of small data type , You must perform forced type conversion , Otherwise, the compiler will report a loss of accuracy error . For example, the landlord , use i To express 1:
short s1 = 1;
int i = 1;
First , because short The type is 16 Bit , and int The type is 32 Bit , It's going on
(s1+i) Operation time , Automatically put s1 Upgrade to 32 position , Then with i Add up , And what you get is 32 Bit , And then
s1=s1+i; Must report wrong , Because if the assignment succeeds , Just lower 16 Bit is assigned to s1, Although this is exactly what the landlord wants , But the compiler cannot determine what your intention is .
Execute forced transfer :
s1=(short)(s1+i); That's fine .
s1+=i; It can compile and get correct results , and s1=s1+i; But report a mistake , Because they are not equivalent ,s1+=i The way java Would be right i Narrow conversion , Automatically executed by the compiler .
边栏推荐
- AUTOCAD——中心线绘制、CAD默认线宽是多少?可以修改吗?
- Word如何显示修改痕迹
- 谷粒商城--分布式高级篇P129~P339(完结)
- Camel case with Hungarian notation
- 深入分析,Android面试真题解析火爆全网
- [depth first search] Ji suanke: Square
- Precautions for binding shortcut keys of QPushButton
- Countdown 2 days | live broadcast preview of Tencent cloud message queue data import platform
- Wx applet learning notes day01
- 业务与应用同步发展:应用现代化的策略建议
猜你喜欢
Reptiles have a good time. Are you full? These three bottom lines must not be touched!
Openmv4 learning notes 1 --- one click download, background knowledge of image processing, lab brightness contrast
Master Xuan joined hands with sunflower to remotely control enabling cloud rendering and GPU computing services
【论文笔记】TransUNet: Transformers Make StrongEncoders for Medical Image Segmentation
ROS custom message publishing subscription example
提前解锁 2 大直播主题!今天手把手教你如何完成软件包集成?|第 29-30 期
Helm deploy etcd cluster
时钟轮在 RPC 中的应用
Tongyu Xincai rushes to Shenzhen Stock Exchange: the annual revenue is 947million Zhang Chi and Su Shiguo are the actual controllers
AIRIOT物联网平台赋能集装箱行业构建【焊接工位信息监控系统】
随机推荐
提前解锁 2 大直播主题!今天手把手教你如何完成软件包集成?|第 29-30 期
Oracle advanced (IV) table connection explanation
时钟轮在 RPC 中的应用
Pychrm Community Edition calls matplotlib pyplot. Solution of imshow() function image not popping up
QPushButton绑定快捷键的注意事项
驼峰式与下划线命名规则(Camel case With hungarian notation)
How are you in the first half of the year occupied by the epidemic| Mid 2022 summary
应用使用Druid连接池经常性断链问题分析
Interview assault 63: how to remove duplication in MySQL?
Php+redis realizes the function of canceling orders over time
Characteristic colleges and universities, jointly build Netease Industrial College
关于图像的读取及处理等
Lucun smart sprint technology innovation board: annual revenue of 400million, proposed to raise 700million
The nearest library of Qinglong panel
Multithreading Basics: basic concepts of threads and creation of threads
Detailed idea and code implementation of infix expression to suffix expression
业务与应用同步发展:应用现代化的策略建议
USB host driver - UVC swap
Swagger2 reports an error illegal DefaultValue null for parameter type integer
史上超级详细,想找工作的你还不看这份资料就晚了