The next JAVA library(2)
えっと、間違ってました(;´Д`)
protected int _width; protected int _height; protected int _wait; //コンストラクタ NewLibrary(){ Integer width = new Integer(240); Integer height = new Integer(240); Integer wait = new Integer(50); _init(width, height, wait); _width = width.intValue(); _height = height.intValue(); _wait = wait.intValue(); }
//メイン側 void _init(Integer width, Integer height, Integer wait){ wait = new Integer(40); }
これ、_waitに入る値は50になりました。
Integerはクラスなので、参照渡しになるはずです。
それなら、その後にnewをすれば書き換わるはずなのに、変化しないのです。
( ・ω・)ナンデ?
あ、もしかしたら、Integer等の、基本型のラッパークラスだけは値渡しになるのでは。
それなら、equals()で比較すれば分か…わか……
equals()がオーバーライドされてるよ( ̄□ ̄;)!!
まあ、多分、Integer等のラッパークラスは、こっそり値渡しをして、equals()は、内部に持っているintの値を比較するんでしょう。
なので、Integerを使って値を書き換えるのは断念。
結局こうしました。
protected int _width; protected int _height; protected int _wait; //コンストラクタ NewLibrary(){ int obj = new int[3][1]; obj[0][0] = 240; obj[1][0] = 240; obj[2][0] = 50; _init(obj[0], obj[1], obj[2]); _width = obj[0][0]; _height = obj[1][0]; _wait = obj[2][0]; }
//メイン側 public void _init(int width, int height, int[] wait){ wait[0] = 40; }
かっこわるー(;´Д`)