您的位置:首页 > 编程语言 > Java开发

Java Puzzlers笔记--puzzle 6: Multicast 类型转换

2007-03-03 19:12 330 查看
 public class Multicast{
 public static void main(String[] args){
  System.out.println((int)(char)(byte) -1);
 }

Solution:
 显示:65535
 byte到char的时候出现问题,byte是由符号的,而在char里是没有符号的。
}

TID:
 the conversion from byte to char is not considered a widening primitive conversion,

but a widening and narrowing primitive conversion: Tye byte is converted to an int and th

int to a char.
 Sign extension is performed if the type of the original value is signed; zero

extension if it is a char ,regardless of the type to which it is being.
 If you can't tell what a program does by looking at it, it probably doesn't do what

you want.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息