java - 自动类型转换如何与 Java 中的“char”一起使用?
问题描述
我不明白这种行为:
int i = 1;
char c = i; // compilation error: incompatible types: possible lossy conversion from int to char
char c = 1; // is OK
前提是整数文字具有默认类型 int。
解决方案
char 是 16 位。
int 至少是 32 位。
除非您向下转换,否则您不能将 32(或更多)位分配给 16 位变量。
向下投射示例:
int kapow = 7;
char blam = (char)kapow;
推荐阅读
- regex - 在bash中替换文件名字符串变量后的字符
- python - 将带有分子和分母的分数转换为二进制
- rest - 如何使用已经存在的 EJB 项目制作宁静的服务?
- amazon-web-services - 即使数据看起来不错,AWS Cloudwatch 警报也不会返回到 OK 状态
- mysql - mysql计算新列的出现次数
- jquery - 从他发布区域外的 $.post 数据中获取返回的数据
- jquery - 如何在间隔和动画中提高每次点击 div 的速度?
- delphi - 无法调用 MessageDlg
- node.js - 从 Visual Studio 将节点应用程序部署到谷歌云
- amazon-web-services - AWS ALB DNS 的安全性