From the course: Java Memory Management: Values and References
Unlock the full course today
Join today to access over 24,900 courses taught by industry experts.
Example custom objects: References on the loose - Java Tutorial
From the course: 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…
Contents
-
-
-
-
-
(Locked)
The problem of escaping references1m 56s
-
(Locked)
Collections and escaping references9m 55s
-
(Locked)
Avoiding escaping collection references6m 36s
-
(Locked)
Example custom objects: References on the loose2m 9s
-
(Locked)
Avoiding escaping references3m 9s
-
(Locked)
Solution: Fixing an escaping reference58s
-
(Locked)
-
-