Why doesn't Java have a copy constructor?
问题 Why doesn't Java support a copy constructor like in C++? 回答1: Java does. They're just not called implicitly like they are in C++ and I suspect that's your real question. Firstly, a copy constructor is nothing more than: public class Blah { private int foo; public Blah() { } // public no-args constructor public Blah(Blah b) { foo = b.foo; } // copy constructor } Now C++ will implicitly call the copy constructor with a statement like this: Blah b2 = b1; Cloning/copying in that instance simply