## 内存 | 1 | 2 | 4 | 8 | | ------- | ----- | ----- | ------ | | byte | short | int | long | | boolean | char | float | double | ##『继承』体系 ```mermaid graph BT A[byte] --> B[short] B --> C[int] C --> D[long] D --> E[float] E --> F[double] G[char] --> C G --> D G --> E G --> F H[boolean] --> I[不参与数值转换] style A fill:#f9f,stroke:#333,stroke-width:2px style B fill:#fcc,stroke:#333,stroke-width:2px style C fill:#cfc,stroke:#333,stroke-width:2px style D fill:#ccf,stroke:#333,stroke-width:2px style E fill:#fcf,stroke:#333,stroke-width:2px style F fill:#cff,stroke:#333,stroke-width:2px style G fill:#ffc,stroke:#333,stroke-width:2px style H fill:#f99,stroke:#333,stroke-width:2px style I fill:#ddd,stroke:#333,stroke-width:2px ``` == 和 + 这类操作时会自动为操作符两边做类型转换到能够等量齐观的级别 ## 精度 // double 的二进制表示 0.05 = 1.1001100110011001100110011001100110011001100110011010 × 2^-5 // 转换回十进制就会得到: 0.05000000000000000277555756156289135105907917022705078125 ## 相加 ![image.png|1000](https://imagehosting4picgo.oss-cn-beijing.aliyuncs.com/imagehosting/fix-dir%2Fpicgo%2Fpicgo-clipboard-images%2F2024%2F08%2F17%2F00-46-18-5f6226435e2ff372685c1a1dd017097b-202408170046852-690a97.png) 1. char、byte、short相加时会自动转换为int类型 2. +=会自动强转(自动装箱功能),但是+必须要手动强转b=(byte)(a+b)。 ## 比较 x == f1[0],x是long类型,与float类型对比属于低精度,所以x要向高精度的float类型转型再比较,故相等;