Copy a Long object in Java
java
Solution
I think, because Long is immutable, you can just use an assignment.
Long a = (long) 1;
Long b = a;
a = (long) 2;
System.out.printf("a=%d, b=%d%n", a, b);
Output is
a=2, b=1
Problem
I think it should be: ``` Long a = Long.valueOf(0); Long b = Long.valueOf(1); Long a = b.clone(); ``` But there is no `clone` method in `Long` object... Maybe `Long a = Long.valueOf(b.LongValue())` will work, but it looks dirty. Is there any nice way to handle this?