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的更多相关文章

  1. Google C++ Style Guide

    Background C++ is one of the main development languages used by many of Google's open-source project ...

  2. 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 ...

  3. Google C++ 代码规范

    Google C++ Style Guide   Table of Contents Header Files Self-contained Headers The #define Guard For ...

  4. Types方法之isCastable-isConvertible

    5. Conversions and Promotions 5.1. Kinds of Conversion 5.1.1. Identity Conversion 5.1.2. Widening Pr ...

  5. 小白的消费为何被迫升级?-java数据类型的转换

    背景 小白最近有点烦恼,原因也很简单,不知道为何?小白的消费不知不觉被迫升级了,请看费用清单: for (byte b = Byte.MIN_VALUE; b < Byte.MAX_VALUE; ...

  6. 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 ...

  7. 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 ...

  8. 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. ...

  9. Modern C++ CHAPTER 2(读书笔记)

    CHAPTER 2 Recipe 2-1. Initializing Variables Recipe 2-2. Initializing Objects with Initializer Lists ...

随机推荐

  1. HDU 1754 I Hate It 2016-09-14 19:01 27人阅读 评论(0) 收藏

    I Hate It Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  2. PAT 甲 1005. Spell It Right (20) 2016-09-09 22:53 42人阅读 评论(0) 收藏

    1005. Spell It Right (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given ...

  3. Sometimes , less is more

    给小团队的特别建议 小团队的普遍现象在于人力紧张,不管是在创业公司还是在大公司内.对于不写代码就手痒的技术人员,如果再在技术上有点儿完美主义情节,那真是可以为代码鞠躬尽瘁的.稍微一整理,事情恨不得已经 ...

  4. underscore chain

    //可以在面向对象或者函数的风格下使用Underscore_.map([1, 2, 3], function(n){ return n * 2; }); //一般习惯用这种 _([1, 2, 3]). ...

  5. 使用for in循环遍历json对象的数据

    使用for in遍历json对象数据,如果数据中的名称有为数字的话,只对正整数有效,那么先会输出为正整数的数据,后面其他的会按照原来数据中定义的顺序不变输出. 针对名称为数字的json对象数据进行测试 ...

  6. Eclipse C++,Cygwin 64,gcov,lcov 单体&覆盖率测试环境搭建笔记

    1.下载并安装 Eclipse IDE for C/C++ Developers https://eclipse.org/downloads/packages/eclipse-ide-cc-devel ...

  7. 使用DbTableColumnWeb项目简要

    项目说明 环境:Vs2013 .Net4.5 MVC5 主要功能:直观编辑表字段说明:生成表对应的实体类:生成数据库表文档说明: 初衷:在开发过程中,经常会遇到同事询问表字段含义.手动编写表对应的实体 ...

  8. C#中的split的基本用法

    split的使用: 1.使用char()字符分隔:根据单个的char()类型的进行分隔 代码如下: string str="e2kdk2fjod2fiksf21"; ');//因为 ...

  9. Ruby on Rails 目录结构

    目录结构 + app/ #控制器.模型.视图.帮助方法.邮件.静态资源 + bin/ #rails脚本 + config/ #路由.数据库等 + db/ #数据库模式.迁移文件 + lib/ #扩展模 ...

  10. .net core Ocelot Consul 实现API网关 服务注册 服务发现 负载均衡

    大神张善友 分享过一篇 <.NET Core 在腾讯财付通的企业级应用开发实践>里面就是用.net core 和 Ocelot搭建的可扩展的高性能Api网关. Ocelot(http:// ...