课程: Java Memory Management: Values and References

今天就学习课程吧!

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

Example custom objects: References on the loose

Example custom objects: References on the loose - Java教程

课程: Java Memory Management: Values and References

Example custom objects: References on the loose

- [Instructor] So at this point, we have seen escaping references in more detail for collections, and this is a very common way to reference escape, but the problem is that all objects that are returned with any precautions have to reference escaping. This is a potential issue for every mutable object. For immutable objects, you don't need to worry about it. They can be accessed from outside, but they cannot be modified anyways. For mutable objects, this is a problem. And whenever an object is extra sensitive or extra accessible, you'll have to create deep copy before returning the object. Let's have a look at an escaping reference example in IntelliJ. So once more, I've created a little demo that is super chaotic and nothing like real production code, but it will demonstrate how references escape in a bit more detail. So, what's going on here? In our main methods, we are creating a user with sensitive object, and we set the secret code, and our sensitive object to 1, 2, 3, 4, 5, 6…

内容