我正在寫一個程序在整個地圖上執行一個星形搜索。我創建了一個保存地圖所有節點的類。在java中改變一個類的數組的值
public Node {
Node up_node, right_node, down_node, left_node;
}
public class Star {
public static void main(String args[]) {
Node a=new Node();
Node b=new Node();
Node h=new Node();
Node here=new Node();
Node[] NextNode;
NextNode = new Node[10];
for(int i=0;i<10;i++) {
NextNode[i]=new Node();
}
int j=0;
a.up_node=h;
a.right_node=b;
b.left_node=a;
h.down_node=a;
//if certain conditions are met
NextNode[j].here_node=a.up_node;
//what i was hoping to do is copy the node a.up which is h
}
}
在這種情況下進入NextNode [0]。但是它會一直返回某種內存地址:[email protected]:test是包的名稱,請幫助!
返回哪裏?如果您嘗試使用system.out.println節點對象,那麼除非您覆蓋類節點的toString方法,否則您將最終得到Node @ XXXX。 – 2013-04-08 19:29:00
除了其他Node的引用之外每個節點中將包含什麼'value'?如果你有'value',那麼在'toString()'方法中返回'value'的'String'格式。這將解決您的問題 – 2013-04-08 19:29:14
「它一直迴歸」非常模糊。目前還不清楚你在哪裏看到的,但幾乎肯定是在'Node'上調用'toString()'的結果 - 並且你沒有重寫該方法... – 2013-04-08 19:29:14