I have the following java code problems
•
Java
public class 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); } }
I'm using this code, but I have a problem: I don't understand why B = B L; No compilation, but if I write B = L; Then it compiles and runs
Please explain why
Solution
This is the advantage of compound assignment operators (such as =, – =, etc.) over assignment operators. You must explicitly convert to the type on the right, but if you use compound assignment operators, it will implicitly perform this operation for you As in your case
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码