Re: [請益]關於型別轉換
※ 引述《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
推
12/01 10:42, , 1F
12/01 10:42, 1F
討論串 (同標題文章)