当前位置:网站首页>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 .
边栏推荐
- 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
- An error occurs when installing MySQL: could not create or access the registry key needed for the
- test about BinaryTree
- 快速幂模板求逆元,逆元的作用以及例题【第20届上海大学程序设计联赛夏季赛】排列计数
- R language ggplot2 visualization: use the ggstripchart function of ggpubr package to visualize the grouped dot strip plot, and set the add parameter to add box plots for different levels of dot strip
- How to improve website weight
- Druid 数据库连接池 详解
- Tongyu Xincai rushes to Shenzhen Stock Exchange: the annual revenue is 947million Zhang Chi and Su Shiguo are the actual controllers
- ROS custom message publishing subscription example
猜你喜欢

Actf 2022 came to a successful conclusion, and 0ops team won the second consecutive championship!!

Solution of commercial supply chain management platform for packaging industry: layout smart supply system and digitally integrate the supply chain of packaging industry

Xingnuochi technology's IPO was terminated: it was planned to raise 350million yuan, with an annual revenue of 367million yuan

About NPM install error 1
![Fast power template for inverse element, the role of inverse element and example [the 20th summer competition of Shanghai University Programming League] permutation counting](/img/dd/c3f4a9c38b156e3a9b9adfd6253773.gif)
Fast power template for inverse element, the role of inverse element and example [the 20th summer competition of Shanghai University Programming League] permutation counting

Intelligent supply chain management system solution for hardware and electromechanical industry: digital intelligent supply chain "creates new blood" for traditional industries

C language daily practice - day 22: Zero foundation learning dynamic planning

Countdown 2 days | live broadcast preview of Tencent cloud message queue data import platform

今日直播 | “人玑协同 未来已来”2022弘玑生态伙伴大会蓄势待发

保证接口数据安全的10种方案
随机推荐
test about BinaryTree
ROS custom message publishing subscription example
PMP practice once a day | don't get lost in the exam -7.6
Three years of Android development, Android interview experience and real questions sorting of eight major manufacturers during the 2022 epidemic
ModuleNotFoundError: No module named ‘PIL‘解决方法
Don't miss this underestimated movie because of controversy!
Based on butterfly species recognition
R language uses rchisq function to generate random numbers that conform to Chi square distribution, and uses plot function to visualize random numbers that conform to Chi square distribution
R语言使用order函数对dataframe数据进行排序、基于单个字段(变量)进行降序排序(DESCENDING)
谷粒商城--分布式高级篇P129~P339(完结)
Master Xuan joined hands with sunflower to remotely control enabling cloud rendering and GPU computing services
青龙面板最近的库
主从搭建报错:The slave I/O thread stops because master and slave have equal MySQL serv
Camel case with Hungarian notation
Mathematical knowledge -- code implementation of Gaussian elimination (elementary line transformation to solve equations)
Dark horse -- redis
黑马--Redis篇
使用map函数、split函数一行键入多个元素
How are you in the first half of the year occupied by the epidemic| Mid 2022 summary
反射及在运用过程中出现的IllegalAccessException异常