For some reason when I create a new instance of an object from an existing instance and change values in the new instance, it also changes the values in the existing instance. I would prefer if it only changed the state of the values in the new instance though. I'm not sure why this is happening.
Foo existing = new Foo(1, "foo");
for (int i = 0; i < 10; i++) {
Foo newFoo = existing;
System.out.println(newFoo.getName()); //Prints "foo" as expected
newFoo.setName("bar");
System.out.println(existing.getName()); //This prints out "bar"?
}
Neither of the objects are static.