将链表数据结构传递给 Java 中的多个 类
Passing a linked list data structure to multiple classes in Java
如何将链表传递给多个 classes?我有一个在 class 中创建的链表,我想将它传递给多个 classes。知道我想避免通过对象传递,因为链表很大并且我想避免内存泄漏。
这应该不是问题,因为您只将对该列表的引用传递给其他对象。这意味着您只有一个大列表。
但是您应该知道,每个引用该列表的对象都可以更改它
那么在 Java 中,您只传递对象 "by reference"...
来自link中的评论:
Let’s be a little bit more specific by what we mean here: objects are
passed by reference – meaning that a reference/memory address is
passed when an object is assigned to another – BUT (and this is what’s
important) that reference is actually passed by value.
如何将链表传递给多个 classes?我有一个在 class 中创建的链表,我想将它传递给多个 classes。知道我想避免通过对象传递,因为链表很大并且我想避免内存泄漏。
这应该不是问题,因为您只将对该列表的引用传递给其他对象。这意味着您只有一个大列表。 但是您应该知道,每个引用该列表的对象都可以更改它
那么在 Java 中,您只传递对象 "by reference"...
来自link中的评论:
Let’s be a little bit more specific by what we mean here: objects are passed by reference – meaning that a reference/memory address is passed when an object is assigned to another – BUT (and this is what’s important) that reference is actually passed by value.