方法传参 “引用赋值”

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.math.BigDecimal;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.omg.SendingContext.RunTime;


public class Test {
   private Date date;
   private String x;
   public static String m;
  
  
 public String getX() {
 return x;
}

public void setX(String x) {
 this.x = x;
}

 public Date getDate() {
 return (Date) date.clone();
}

   public void setDate(Date date) {
 this.date = date;
}

 /**
  * @param args
  * @throws IOException
  */
 public static void main(String[] args) throws IOException {
     Test t = new Test();
      t.setX("a");
     Test t2 = new Test();
     t2.setX("b");
     swap(t,t2);
     System.out.println(t.getX()+"    " +t2.getX());
     //如果传递的是引用的话
     Test tem = new Test();
      tem =t;
      t = t2;
      t2 =tem;
      System.out.println(t.getX()+"    " +t2.getX());
 } 
 public static void swap(Test x , Test y){
  Test tem = new Test();
  tem =x;
  x =y;
  y = tem;
 }

}

你可能感兴趣的:(java,.net)