引用类型参数的传递,调用方的变量,和接收方的参数变量,地址指向的是同一个对象。
双方任意一方对这个对象的修改,都会影响对方
myself:这样也不用像php加&,说变就跟着变,会不会很麻烦,出现一些隐匿的bug
public class ImoocStudent {
public void replaceFirstPlayer(String[] players,String playerName){
System.out.println("将第一个球员替换:");
players[0] = playerName;
}
public static void main(String[] args){
String[] players = {"詹姆斯","科比","杜兰特","乔丹"};
System.out.println("球队中现有球员:");
for(String player : players){
System.out.println(player + "\t");
}
System.out.println();
ImoocStudent lei = new ImoocStudent();
lei.replaceFirstPlayer(players,"job");
System.out.println();
for(String player : players){
System.out.println(player + "\t");
}
}
}
标签:java,String,player,System,players,引用,println,传值,out
From: https://www.cnblogs.com/pansidong/p/17417595.html