如果我们在方法中定义对象,那么该obj将存储在哪里? [英] if we define object in method then where will be store that obj?

查看:96
本文介绍了如果我们在方法中定义对象,那么该obj将存储在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我们在方法中定义对象,那么该对象将在Java中堆栈或堆中存储在哪里?

有人可以给我一个吗?

if we define object in method then where will be store that object in stack or heap in java?

can anyone give me ans please?

推荐答案

由于您说过将创建一个对象,因此该对象将存在"于堆中.该方法本地的变量实际上将保存对所创建对象的引用,该变量将存在"于堆栈中.当实例化一个类时,将创建该类型的对象,并进一步使用该实例,您必须将其分配给适当类型的变量.

请阅读此处以获得更好的综述: .NET中的C#堆与堆栈 [^ ]

问候,

曼弗雷德(Manfred)
Since you said an object will be created, this object will "live" on the heap. The variable local to the method, which will in fact hold the reference to said created object, will "live" on the stack. When you instantiate a class an object of that type will be created and to further use that instance you''ll have to assign it to a variable of the proper type.

Please read here for a nice roundup: C# Heap(ing) Vs Stack(ing) in .NET [^]

Regards,

Manfred


这篇关于如果我们在方法中定义对象,那么该obj将存储在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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