これはばかげているように思えるかもしれませんが、すべての船の位置を保存したい船の位置と呼ばれるクラスがあり、それをクライアントクラスから拡張し、次のようにsetメソッドを呼び出しました。sub.localは船のクラスからの多次元配列です
sub.local = new int[2][2];
sub.local[0][0] =row;
sub.local[0][1]=col;
sub.local[1][0]=row;
sub.local[1][1] =col+1;
toServer.writeInt(row);
toServer.writeInt(col);
toServer.writeChar('s');
sub.placed=true;
setp1sub(sub.local);
別のクラスで印刷すると、必要な数値ではなく、メモリ内の場所が返されます。これの理由は何ですか
public class ShipLocations {
static int [][] p1sub;
public ShipLocations()
{
p1sub = new int[2][2];
}
public int[][] getp1sub()
{
return p1sub;
}
public void setp1sub(int[][] local) {
for (int i = 0;i <local.length;i++)
{
for(int j = 0;j<local.length;j++)
{
p1sub [i][j]= local[i][j];
}
}
}
}
それを sub.local として渡しているのでしょうか?出力は [[I@a401c2