当前位置:网站首页>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 .
边栏推荐
- 青龙面板最近的库
- test about BinaryTree
- JDBC详解
- swagger2报错Illegal DefaultValue null for parameter type integer
- C language daily practice - day 22: Zero foundation learning dynamic planning
- 时钟轮在 RPC 中的应用
- 受益匪浅,安卓面试问题
- 打家劫舍III[后序遍历与回溯+动态规划]
- Mathematical knowledge -- code implementation of Gaussian elimination (elementary line transformation to solve equations)
- Benefit a lot, Android interview questions
猜你喜欢
The list of people who passed the fifth phase of personal ability certification assessment was published
LeetCode-1279. 红绿灯路口
Wx applet learning notes day01
数学知识——高斯消元(初等行变换解方程组)代码实现
Yutai micro rushes to the scientific innovation board: Huawei and Xiaomi fund are shareholders to raise 1.3 billion
Airiot IOT platform enables the container industry to build [welding station information monitoring system]
pychrm社区版调用matplotlib.pyplot.imshow()函数图像不弹出的解决方法
Digital "new" operation and maintenance of energy industry
MRO工业品企业采购系统:如何精细化采购协同管理?想要升级的工业品企业必看!
A method of removing text blur based on pixel repair
随机推荐
Countdown 2 days | live broadcast preview of Tencent cloud message queue data import platform
R语言使用rchisq函数生成符合卡方分布的随机数、使用plot函数可视化符合卡方分布的随机数(Chi Square Distribution)
A full set of teaching materials, real questions of Android interview of 7 major manufacturers including Alibaba Kwai pinduoduo
ModuleNotFoundError: No module named ‘PIL‘解决方法
反射及在运用过程中出现的IllegalAccessException异常
Is not a drawable (color or path): the vector graph downloaded externally cannot be called when it is put into mipmap, and the calling error program crashes
Interface test tool - postman
Multithreading Basics: basic concepts of threads and creation of threads
[depth first search] Ji suanke: a joke of replacement
MRO industrial products enterprise procurement system: how to refine procurement collaborative management? Industrial products enterprises that want to upgrade must see!
Reptiles have a good time. Are you full? These three bottom lines must not be touched!
pytorch常见损失函数
通俗的讲解,带你入门协程
Fast power template for inverse element, the role of inverse element and example [the 20th summer competition of Shanghai University Programming League] permutation counting
三面蚂蚁金服成功拿到offer,Android开发社招面试经验
Characteristic colleges and universities, jointly build Netease Industrial College
黑马--Redis篇
Documents to be used in IC design process
Synchronous development of business and application: strategic suggestions for application modernization
Meilu biological IPO was terminated: the annual revenue was 385million, and Chen Lin was the actual controller