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.
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.
相关文章推荐
- Java类型强制转换小笔记
- Java Puzzlers笔记--puzzle 9: Tweedledum +=的问题
- Java默认类型,类型转换,常量与变量笔记
- 厨娘的Java笔记(一):强制类型转换之引用转换
- Java学习笔记8. 数据类型的转换
- java笔记之封装、继承、重写、多态以及类型转换
- 小白Java笔记——基本类型的类型转换和表达式类型的自动提升
- Java Puzzlers笔记--puzzle 10: Tweedledee += 问题(2)
- java 从零开始,学习笔记之基础入门<数据类型的转换>(五)
- java笔记之封装、继承、重写、多态以及类型转换
- Java 笔记 之 类型转换
- java学习笔记三——数据类型转换
- Java Puzzlers笔记--Puzzle 3: Long Division 溢出问题
- Java Puzzlers笔记--puzzle 17: Huh? 转义字符问题
- Java复习笔记----变量定义、数据类型转换
- 黑马程序员—Java基础学习笔记之数据类型转换(自动转换和强制转换)
- java笔记之封装、继承、重写、多态以及类型转换
- Java 笔记 之 类型转换
- daliu_it java基础笔记之 变量和数据类型以及数据类型之间的转换以及转义字符
- Core Java 学习笔记——2.基本数据类型&类型转换