简体   繁体   English

java中如何通过引用传递引用

[英]how to pass reference by reference in java

I have BST that implements by linked list and I want to find an object by id of my nodes by start searching from the root and put it in key.我有通过链表实现的 BST,我想通过从根开始搜索并将其放入键中,通过节点的 id 找到一个对象。 so I have to pass the reference by reference , not by value;所以我必须通过引用传递引用,而不是通过值; how can I do that?(key is a variable that declare out of function) enter image description here我该怎么做?(键是一个声明函数外的变量)在此处输入图像描述

You can't pass by reference in Java.在 Java 中不能通过引用传递。

You can emulate pass-by-reference by holding the "variable" as an element in an array or field in an object, and pass the reference to that array or object, and that will allow changes to the "variable" to be shared between scopes.您可以通过将“变量”作为数组或对象中的字段中的元素保存来模拟传递引用,并将引用传递给该数组或对象,这将允许在“变量”之间共享更改范围。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM