课程: Java Memory Management: Values and References

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Avoiding escaping references

Avoiding escaping references

- [Instructor] So how to fix these escaping references? Well, in order to start, we'll need to make user cloneable, so we say influence clonenable and then, below, we are actually overriding the clone function. And actually you always have to override the clone function. Also, if you don't want to modify it at all and just want to super of clone, because clones protect it in the optic class. So you'll have to override it, even if you're not going to do anything fancy, but we need to do something special here. In the previous example, we didn't have any mutable properties, but our user it has a mutable property and the mutable property is our sensitive object. So the clone management is using this super dot clone and then, for all the mutual properties, it's going to create a clone as well. And the clone is doing nothing more than creating a shallow copy. So you have to do this for every object as mutable objects itself, because then the shallow copy is not enough. Luckily for us, it…

内容