作者ogamenewbie (._.)
看板java
标题Re: [请益]关於型别转换
时间Mon Dec 1 00:49:39 2008
※ 引述《vic1225 (/* I'm not worth */)》之铭言:
: 在java中
: byte a, b, c;
: a = b + c;
: b , c 会被先转成int然後相加
: 然後何在转成byte指定给a
: 这应该是表示 int 的范围比byte小吧
你如果有用 ide 的话,
比较会抓警告错误状况的会跟你说 possible loss of precision
请你改成 a = (byte) (b + c);
另外, API 里面 Byte Class 的 Field Summary 中
static byte MAX_VALUE
A constant holding the maximum value a byte can have, 2^7-1.
static byte MIN_VALUE
A constant holding the minimum value a byte can have, -2^7.
Integer Class 的 Field Summary 中
Field Summary
static int MAX_VALUE
A constant holding the maximum value an int can have, 2^31-1.
static int MIN_VALUE
A constant holding the minimum value an int can have, -2^31.
: 还是??
: byte -> int in java
: 相当於
: double -> int 还是 int -> double in C 呢
: 感激不尽~!
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 218.160.34.54
1F:推 vic1225:谢谢不吝赐教~! 12/01 10:42