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 ...
随机推荐
- 微信post xml 消息编码问题
site:mp.weixin.qq.com utf 微信卡券接口说明 - 微信公众平台开发者文档 所有API接口POST的数据只支持utf8编码,否则会返回报错. 以上是获取的部分信息 这个尽管有点模 ...
- ESP32应用程序的内存布局
应用程序内存布局 ESP32芯片具有灵活的内存映射功能.本节介绍ESP-IDF在默认情况下如何使用这些功能. ESP-IDF中的应用程序代码可以放置在以下内存区域之一中. IRAM(指令RAM) ES ...
- APUE(5)---标准I/O库 (3)
十.定位流 #include <stdio.h> long ftell(FILE *fp); //若成功,返回当前文件位置指示:若出错,返回-1L int fseek(FILE *fp, ...
- 【算法33】LRU算法
题目来源 LeetCode: https://leetcode.com/problems/lru-cache/ LRU简介 LRU (Least Recently Used,最近最少使用)算法是操作系 ...
- SQL Server Extended Events 进阶 1:从SQL Trace 到Extended Events
http://www.sqlservercentral.com/articles/Stairway+Series/134869/ SQL server 2008 中引入了Extended Events ...
- .net core使用NLog记录
首先使用Nugut安装NLog, NLog.Extensions.Logging,using NLog.Web,并且加上配置文件 ”nlog.config“,配置文件内容网上都可以百度的到.这是我自己 ...
- ADO.NET系列之DataAdapter对象
ADO.NET系列之Connection对象 ADO.NET系列之Command对象 ADO.NET系列之DataAdapter对象 ADO.NET系列之事务和调用存储过程 我们前两篇文章介绍了ADO ...
- sqlServer数据库常用连接字符串
sqlServer 数据库常用连接字符串 用户名和密码验证的方式去连接到数据库服务器 <add name="conStr" connectionString=" ...
- S11 day 95 RestFramework 之 视图
1. 基于APIVIEW视图序列化 我们会发现两个类有好多重复的代码.所以我们引入了GenericAPIView (继承了APIView) 2.Generic ApiVIew和 ListModel ...
- 前端入门html(常用标签及标签分类)
day47 参考:https://www.cnblogs.com/liwenzhou/p/7988087.html 任何标签都有有三个属性:ID,class.style <!DOCTYPE ht ...