Chapter 5. Conversions and Promotions
JLS解读:https://docs.oracle.com/javase/specs/jls/se7/html/jls-5.html
基本数据类型的转换
1) boolean不可以转换为其他的数据类型
2) 整数型,浮点类型,字符型是可以相互转换的,转换时遵守下面的原则:
a. 容量小的类型自动转换为大的类型,数据类型按容量大小排序为:
byte, short, char < int < long <float < double
b. byte, short, char 三种类型间不会相互转换,他们三者在计算时,首先会转换为int类型
c. 容量大的类型在转换为小的类型的时候,必须加上强制转换符,此时可能造成精度降低或者溢出问题
d. 有多种数据类型混合计算的时候,系统首先自动转换为容量最大的那个类型再来继续计算100 + 300 +0L 在计算时,首先是100+300的整数计算,然后与0L相加,结果为long类型的
e. 实数类型默认为double类型,整数类型默认为int类型
如图所示:

Chapter 5. Conversions and Promotions的更多相关文章
- Google C++ Style Guide
Background C++ is one of the main development languages used by many of Google's open-source project ...
- Julia is a high-level, high-performance dynamic programming language for technical computing, with syntax that is familiar to users of other technical
http://julialang.org/ julia | source | downloads | docs | blog | community | teaching | publications ...
- Google C++ 代码规范
Google C++ Style Guide Table of Contents Header Files Self-contained Headers The #define Guard For ...
- Types方法之isCastable-isConvertible
5. Conversions and Promotions 5.1. Kinds of Conversion 5.1.1. Identity Conversion 5.1.2. Widening Pr ...
- 小白的消费为何被迫升级?-java数据类型的转换
背景 小白最近有点烦恼,原因也很简单,不知道为何?小白的消费不知不觉被迫升级了,请看费用清单: for (byte b = Byte.MIN_VALUE; b < Byte.MAX_VALUE; ...
- Integral Promotions整数提升和符号扩展(char,unsigned char,signed char)
以下来自msdn: Objects of an integral type can be converted to another wider integral type (that is, a ty ...
- JVM Specification 9th Edition (4) Chapter 3. Compiling for the Java Virtual Machine
Chapter 3. Compiling for the Java Virtual Machine 内容列表 3.1. Format of Examples 3.2. Use of Constants ...
- JVM Specification 9th Edition (3) Chapter 2. The Structure of the Java Virtual Machine
Chapter 2. The Structure of the Java Virtual Machine 内容列表 2.1. The class File Format (class文件的格式) 2. ...
- Modern C++ CHAPTER 2(读书笔记)
CHAPTER 2 Recipe 2-1. Initializing Variables Recipe 2-2. Initializing Objects with Initializer Lists ...
随机推荐
- loadrunner提高篇 - 关联技术的经典使用
关联函数是一个查找函数,即是从HTML文件内容中查找需要的值,并将其保存在一个变量或数组中.换一个角度看,关联函数不单单可以匹配一些变化的值,同样可以匹配一些固定的内容,并将其保存到一个数据组,供后续 ...
- (最短路 Floyd)Cow Contest --POJ--3660
链接: http://poj.org/problem?id=3660 思路: 1. 1->2->3==1->3 2. 记录每次的比赛人员 3. 每个人只能跟他序号不同的人比赛, ...
- Hdu3363 Ice-sugar Gourd 2017-01-16 11:39 43人阅读 评论(0) 收藏
Ice-sugar Gourd Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- windows eclipse IDE打开当前类所在文件路径
1. 展开如下菜单: Run ---- External Tools ---- External Tools Configurations 2. 在 program 下面新建一个工具 program- ...
- WebApi使用JWT认证(一)
这是第一部:先实现NetFramework上的WebApi使用JWT认证 1.VS新建一个WebApi项目 2.项目右键----管理Nuget程序包----找到JWT,然后安装 3.Model文件夹下 ...
- Python学习-29.Python中列表的一些操作
in关键字: 注意这个是关键字,用来判断元素是否在集合中存在. list = ['a','b','c'] print('a' in list) print('f' in list) 将依次输出 Tru ...
- Alwayson--问题总结一
1. Alwayson 是否依赖于域环境? 答: 是, alwayson依赖于故障转移群集(只有在故障转移群集中的SQL Server 才能启动高可行性组功能),而故障转移群集愈依赖于域环境. 2. ...
- net_framework-EF CodeFirst
CodeFirst——手动创建POCO类(Plain Old CLR Object,即平时认识的ado.net实体类),类之间的关系使用代码定义.当应用程序首次执行时,EF将在数据库服务器中自动生成数 ...
- C#中获取用户登录IP地址
using System.Net; //导入命名空间 public string getLocalIP() { string strHostName = Dns.GetHostName(); //得到 ...
- Map 综述(三):彻头彻尾理解 ConcurrentHashMap
https://blog.csdn.net/justloveyou_/article/details/72783008