java hashmaps的get()函数 [英] the get() function for java hashmaps

查看:163
本文介绍了java hashmaps的get()函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我宣布了以下hashmap:

  HashMap< Integer,Hive> hives 

其中Hive是一个对象。

如果我调用hives.get(2),它是否会在该位置返回对象Hive的副本或对该对象的引用?



我的目标是修改该位置的Hive对象。如果它返回引用,我可以修改返回的配置单元并完成。但是,如果一个副本被返回,那么我将不得不将这个副本放回到hashmap中。



对不起,这个简单的问题。我试图寻找一个解决方案,但我看到它的每个地方只是说它的价值会被返回,它并没有说它是否是价值的副本或对它的引用。



感谢,
Zain

解决方案

它返回一个引用。除非另有说明,否则几乎可以认为情况正是如此。


I've declared the following hashmap:

HashMap<Integer, Hive> hives

Where Hive is an object.

If I call "hives.get(2)" will it return a copy of the object Hive at that location or a reference to it?

My goal is to modify the Hive object at that location. If it returns the reference, I can just modify the returned hive and be done. However, if a copy gets returned then I'll have to put that copy back into the hashmap.

Sorry for the simple question. I tried looking around for a solution, but everywhere I looked it simply said the value would be returned, it didn't say if it would be a copy of the value or a reference to it.

Thanks, Zain

解决方案

It returns a reference. You can pretty much assume this is the case unless otherwise specified.

这篇关于java hashmaps的get()函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆