为什么我们不能在Java中使用指针? [英] Why can't we use pointers in Java?
问题描述
为什么我们不在这里使用指针?
Why we are not using the pointer here?
在Java中使用哪个概念代替指针?
Which concept is used instead of pointer in Java?
推荐答案
为什么我们不能在Java中使用指针?
Why can't we use pointers in Java?
因为语言设计者选择不在语言中包含指针。
Because the language designers chose not to include pointers in the language.
为什么我们不在这里使用指针。
Why we are not using the pointer here.
因为设计师Java认为它是一个难以使用且容易出错的构造。
Because the designers of Java thought it was a tricky-to-use and error prone construct.
使用哪个概念代替Java中的指针?
Which concept is used instead of pointer in Java?
引用(如果忽略指针算法,它与指针非常相似) 。
References (which are quite similar to pointers if you disregard from pointer arithmetic).
请记住,您在堆上创建的所有对象(使用 new
关键字)。这个事实,以及没有解除引用运算符(C / C ++中的 *
)的事实意味着没有办法获取对象!由于无法获取对象,因此无法将对象存储在变量中。因此,所有变量(包含原始类型的变量除外)都是引用类型。
Keep in mind that all objects you create, you create on the heap (using the new
keyword). This fact, together with the fact that there is no "dereference operator" (*
in C/C++) means that there's no way to get hold of an object! Since you can't get hold of an object, there's no way you can store an object in a variable. Therefor all variables (except the ones holding primitive types) are of reference-type.
这篇关于为什么我们不能在Java中使用指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!