Are there any alternatives to implementing Clone in Java?

前端 未结 5 1204
醉酒成梦
醉酒成梦 2021-01-12 15:10

In my Java project, I have a vector of various types of Traders. These different types of traders are subclasses of the Trader class. Right now, I have a method that takes a

5条回答
  •  长发绾君心
    2021-01-12 15:54

    Uri's right, polymorphism with state opens up a big can of worms.

    I think subclassing Cloneable and overrideing clone() is probably the simplest way to go. You can, I believe, make the return type covariant.

提交回复
热议问题