java - 原始类型和引用类型有什么区别?

标签 java types reference primitive

这是一个过去的考试问题,我想知道什么是原始类型和引用类型? 对于数组,我知道引用类型是数组由对象或变量组成的地方,但原始类型是您可以仅使用 int 或字符串创建数组的地方。 (对吧?)

你认为你会如何回答考试中的问题并获得良好的评价?没有真正直接引用原始 ARRAY 类型......有没有办法做到这一点?还是你觉得用数组来解释就好了。

最佳答案

从书 OCA JAVA SE 7

Just as men and women are fundamentally different (according to John Gray, author of Men Are from Mars, Women Are from Venus), primitive variables and object reference variables differ from each other in multiple ways. The basic difference is that primitive variables store the actual values, whereas reference variables store the addresses of the objects they refer to. Let’s assume that a class Person is already defined. If you create an int variable a, and an object reference variable person, they will store their values in memory as shown in figure 2.13.

int a = 77;
Person person = new Person();

enter image description here

关于java - 原始类型和引用类型有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8790809/

相关文章:

java - 快速排序分区

java - 在 Tomcat 中部署 Web 应用程序

c++ - 相当于 Go 中的 sizeof(aType)

postgresql - 在 PostgreSQL 中存储 UUID 的最佳数据类型是什么?

c++ - 按值返回的内存管理差异

欢笑中的 Java 堆大小错误

c - size_t 迭代的可变尺度

rust - 难以管理引用和取消引用的组合

c# - 如何安全地将字符串引用从 C# 传递到 C++?

java - 找出数据库死锁