求助~(java链表关于对象的引用,与传递和修改。)硬是没看懂
class Link{
public int iDate;
public double dDate;
public Link next;
public Link(int i,double d){
iDate=i;
dDate=d;
}
public void displayLink(){
System.out.println("iDate=="+iDate+", dDate=="+dDate);
}
}
public class LinkList {
/**
* @param args
*/
public Link first;
public LinkList(){
first=null;
}
public void insertFirst(int i,double d){
Link newLink=new Link(i,d);
newLink.next=first;
first=newLink;
}
public void displayLink(){
System.out.println("链表显示");
Link curren=first;
while(curren!=null){
curren.displayLink();
curren=curren.next;
}
}
public void test(){
Link curren=first;
System.out.println(curren.hashCode()+"~~~~~~~"+first.hashCode());//测试结果 7051261~~~~~~~7051261
/*first=first.next;
System.out.println(curren.hashCode()+"~~~~~~~"+first.hashCode());//测试结果 7051261~~~~~~~29855319
*/
/* Link pre=first.next;
pre=first.next.next;
first.next=first.next.next;*/ // 这两个代码的执行结果有撒区别
first.next=first.next.next;
System.out.println(curren.hashCode()+"~~~~~~~"+first.hashCode());//测试结果 7051261~~~~~~~7051261
}
public static void main(String[] args) {
// TODO Auto-generated method stub
LinkList ll=new LinkList();
ll.insertFirst(1, 88);
ll.insertFirst(2, 99);
ll.insertFirst(3, 100);
ll.insertFirst(4, 105);
ll.insertFirst(5, 323);
ll.test();
}
}
重点test()方法为什么两次的测试结果不一样,
/*first=first.next;
System.out.println(curren.hashCode()+"~~~~~~~"+first.hashCode());//测试结果 7051261~~~~~~~29855319
*/
first.next=first.next.next;
System.out.println(curren.hashCode()+"~~~~~~~"+first.hashCode());//测试结果 7051261~~~~~~~7051261