So can anyone give a live example of a language that follows a link, whose example we could link is that java does not follow a link
Pass-by-ref vs pass-by-value .
void swap(String a, String b) {
String c = b;
b = a;
a = c;
}
void main() {
String a = "A";
String b = "B";
swap(a, b);
System.out.println(a);
System.out.println(b);
}
, main.a , swap.a, "A".
vs # (IDE One), .
void Swap(ref string a, ref string b) {
string c = b;
b = a;
a = c;
}
void main() {
string a = "A";
string b = "B";
Swap(ref a, ref b);
Console.WriteLine(a);
Console.WriteLine(b);
}
main.a swap.a , swap.a main.a.
,
void swap(StringBuilder a, StringBuilder b) {
String a1 = a.toString();
String b1 = b.toString();
a.setLength(0);
a.append(b1);
b.setLength(0);
b.append(a1);
}
void main(){
StringBuilder a = new StringBuilder("A");
StringBuilder b = new StringBuilder("B");
swap(a, b);
System.out.println(a);
System.out.println(b);
}
, , . :
public static void main(String... agv){
StringBuilder a = new StringBuilder("A");
StringBuilder b = new StringBuilder("B");
StringBuilder alsoA = a;
swap(a, b);
System.out.println(a);
System.out.println(b);
System.out.println(alsoA);
}
vs # (IDEOne)
void Main() {
string a = "a";
string b = "b";
string alsoA = a;
Swap(ref a, ref b);
Console.WriteLine(a);
Console.WriteLine(b);
Console.WriteLine(alsoA);
}
Java Ranch , .