当前位置:网站首页>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 .
边栏推荐
- usb host 驱动 - UVC 掉包
- Unlock 2 live broadcast themes in advance! Today, I will teach you how to complete software package integration Issues 29-30
- C # - realize serialization with Marshall class
- openmv4 学习笔记1----一键下载、图像处理背景知识、LAB亮度-对比度
- R language ggplot2 visualization: use the ggdotplot function of ggpubr package to visualize dot plot, set the palette parameter, and set the colors of data points and box graphs of dot plots at differ
- 三面蚂蚁金服成功拿到offer,Android开发社招面试经验
- AUTOCAD——中心线绘制、CAD默认线宽是多少?可以修改吗?
- How to improve website weight
- Sanmian ant financial successfully got the offer, and has experience in Android development agency recruitment and interview
- 关于图像的读取及处理等
猜你喜欢
应用使用Druid连接池经常性断链问题分析
Looting iii[post sequence traversal and backtracking + dynamic planning]
反射及在运用过程中出现的IllegalAccessException异常
ROS自定义消息发布订阅示例
Solution of intelligent management platform for suppliers in hardware and electromechanical industry: optimize supply chain management and drive enterprise performance growth
Interface test tool - postman
Digital "new" operation and maintenance of energy industry
五金机电行业智能供应链管理系统解决方案:数智化供应链为传统产业“造新血”
[matlab] Simulink the input and output variables of the same module cannot have the same name
三年Android开发,2022疫情期间八家大厂的Android面试经历和真题整理
随机推荐
PMP每日一练 | 考试不迷路-7.6
Multithreading Basics: basic concepts of threads and creation of threads
R language uses DT function to generate t-distribution density function data and plot function to visualize t-distribution density function data
Solution of intelligent management platform for suppliers in hardware and electromechanical industry: optimize supply chain management and drive enterprise performance growth
How are you in the first half of the year occupied by the epidemic| Mid 2022 summary
Master Xuan joined hands with sunflower to remotely control enabling cloud rendering and GPU computing services
Word如何显示修改痕迹
关于静态类型、动态类型、id、instancetype
R语言使用order函数对dataframe数据进行排序、基于单个字段(变量)进行降序排序(DESCENDING)
[depth first search] Ji suanke: a joke of replacement
openmv4 学习笔记1----一键下载、图像处理背景知识、LAB亮度-对比度
When visual studio code starts, it prompts "the code installation seems to be corrupt. Please reinstall." Solution to displaying "unsupported" information in the title bar
Benefit a lot, Android interview questions
R language ggplot2 visual time series histogram: visual time series histogram through two-color gradient color matching color theme
Characteristic colleges and universities, jointly build Netease Industrial College
黑马--Redis篇
php+redis实现超时取消订单功能
An error occurs when installing MySQL: could not create or access the registry key needed for the
多线程基础:线程基本概念与线程的创建
USB host driver - UVC swap