0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

連想配列、List,Arraylist、キャスト、参照

Posted at

連想配列は便利だけどメソッドで返せない。

ArraylistかListなら返せる。

Arraylistだと何でもバンバン突っ込めるがObject型なので
明示キャストが必要。あと参照外れる。

Listなら当たり前だけどキャスト要らないし参照も外れない。

テスト時にArraylistで組んでて
コードレビュー受けてListにしたらキャストの手間も要らないし
参照も外れないから全件検索の必要なくなるよ
ってコードで言われて赤面しました。

あと配列はシャローコピーとディープコピーがあるらしく
一次レイヤーは値コピー、参照コピーの使い分けができるけど
二次レイヤー以下は参照コピー扱いになっちゃって毎回初期化してた。
ここの解決策ほしい。

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?