I tried to simulate pass-by-ref in java by passing an array of size 1 that contains the value to a corresponding method.
The source:
public static void test(String... a) {
a[0] = new String("bar");
}
public static void main(String[] args) throws Exception {
String a = "foo";
test(a);
System.out.println(a);
}
The value is still "foo" - why? I use JDK version 15.0.1.