I'm trying to copy a source element into an existing destination element. It works fine in the method but the reference in the main method doesn't change. What is my mistake?
public class Bounds {
public static <T extends Number> void copy(Paar<? extends Number> src, Paar<? extends Number> dst) {
// src = (1, 2) dst = (1.1, 2.2)
T c1 = (T) src.p1;
T c2 = (T) src.p2;
dst = new Paar<>(c1, c2);
System.out.println("Src:" + src);
System.out.println("Dst:" + dst);
// src = (1, 2) dst = (1, 2)
}
}
public class BoundsMain {
public static void main(String[] args) {
Integer[] iFeld = { 1, 2, 3 };
Number[] nFeld = { 1.1, 2.2, 3.3 };
Paar<Integer> src = new Paar<>(iFeld[0], iFeld[1]);
Paar<Number> dst = new Paar<>(nFeld[0], nFeld[1]);
System.out.println("src=" + src + "\ndst vor copy =" + dst );
// src = (1, 2) dst = (1.1, 2.2)
Bounds.copy(src, dst);
System.out.println("src nach copy =" + src);
System.out.println("dst nach copy =" + dst);
// src = (1, 2) dst = (1.1, 2.2)
}
}