课程: Java Memory Management: Values and References
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Collections and escaping references - Java教程
课程: Java Memory Management: Values and References
Collections and escaping references
- [Micah] Collections can hold multiple objects, and they do so by holding multiple references to all these objects. It is common that when you return the collection from a method that you make a clone of this collection because a collection is an object itself. And when you return a collection, sometimes you don't want to share to the reference. And if that's the case, you have to make a clone. 'Cause if you make a clone, you cannot modify the collection from another place using reference. So for example, something gets added or something gets removed, this won't happen to your original place because it's a new reference and a new object. So in these cases, you'll return a clone of your collection. Let's have a look at an example in IntelliJ to see this in action. All right, so I've made little demo here, and clearly, this is poorly structured code and this looks terrible, but it's just for the purpose of explaining what's going on with collections and references and more…
内容
-
-
-
-
-
(已锁定)
The problem of escaping references1 分钟 56 秒
-
(已锁定)
Collections and escaping references9 分钟 55 秒
-
(已锁定)
Avoiding escaping collection references6 分钟 36 秒
-
(已锁定)
Example custom objects: References on the loose2 分钟 9 秒
-
(已锁定)
Avoiding escaping references3 分钟 9 秒
-
(已锁定)
Solution: Fixing an escaping reference58 秒
-
(已锁定)
-
-