Java char to byte casting
问题 I have been testing the char casting and I went through this: public class Test { public static void main(String a[]) { final byte b1 = 1; byte b2 = 1; char c = 2; c = b1; // 1- Working fine c = b2; // 2 -Compilation error } } Can anyone explain why it's working fine in 1 when I added a final to the byte? 回答1: When the variable is final , the compiler automatically inlines its value which is 1. This value is representable as a char , i.e.: c = b1; is equivalent to c = 1; In fact, according to