關於Integer的小問題

2021-08-31 07:04:42 字數 652 閱讀 3076

最近看到書上有一段**讓寫出輸出結果:

integer a = 1;

integer b = 1;

system.out.println(a==b);

system.out.println(a.equals(b));

當時不假思索的就認為結果是false,true.

拿到機器上執行結果是true,true.

通過請教他人才知道,integer回對(-128-127)區間的值進行快取。說是這樣在效率和空間上比構造方法更好。

integer a = 128;

integer b = 128;

system.out.println(a==b);

system.out.println(a.equals(b));

此時,結果就是false,true.

integer a = new integer(1);

integer b = new integer(1);

system.out.println(a==b);

system.out.println(a.equals(b));

此時,結果是false,true.因為建立了兩個物件。申請了兩個不同的空間。

關於 Integer 值比較的問題

今天剛好遇到這樣的問題,別的不說,先上 public class testinteger 大家看一下這一段 是不是很簡單呢。大家心裡也有答案了吧?好的,看一下我們執行之後的答案 a b false c d true 是不是有點意外,這是為什麼呢?來簡單說一下這個 所以以後如果我們碰到這種需要怎麼去比...

關於fork的小問題

在閱讀apue的時候,試著在cygwin中測試乙個源程式,如下 1 include 2 include 3 include 4 include 56 define maxline 512 7 static void sig int int 8 int main int argc,char argv ...

關於m pMainWnd的小問題

m pmainwnd new cmainwindow 這句新建了乙個cmainwindow類物件,並將其位址賦給m pmainwnd,以後用這個指標來操作此物件 m pmainwnd showwindow m ncmdshow 這句決定了cmainwindow物件 派生自cframewnd類,這是乙...