我有以下Java代码的问题
发布时间:2020-12-15 05:16:12 所属栏目:Java 来源:网络整理
导读:public class b { public static void main(String[] args) { byte b = 1; long l = 127; // b = b + l; // 1 if I try this then it does not compile b += l; // 2 if I try this then it does compile System.out.println(b); }} 我正在使用此代码,但我有
public class b { public static void main(String[] args) { byte b = 1; long l = 127; // b = b + l; // 1 if I try this then it does not compile b += l; // 2 if I try this then it does compile System.out.println(b); } } 我正在使用此代码,但我有问题: 请解释为什么会这样. 解决方法
这就是复合赋值运算符(如=,– =等)优于赋值运算符的优点,您必须明确地转换为右侧的类型,但如果使用复合赋值运算符,它会隐式为您执行此操作. 正如你的情况一样.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- java – 如何使用JEE7 Websockets将参数传递给@OnOpen方法,
- java – 从数据库中读取BLOB(PDF内容)并编辑和输出PDF编辑
- RSA非对称加密解密Java实例代码
- java – 使用Hibernate工具从数据库为单个表生成.hbm文件
- Java检查异常不在函数的throw规范中?
- JSP application.getNamedDispatcher()方法:根据指定参数名
- ScheduledExecutorService任务定时代码示例
- java – 尝试从另一个方法捕获
- java – 如何仅跳过“编译”和“安装”目标的测试而不跳过“
- 在实践中使用Selenium 2.0 WebDriver