在内部,对象的引用被实现为指针。虽然没有指针算法......
C++有指针,因为它是作为C的超集构建的,它有指针。 C有指针,因为它是在60年代设计的。那时计算机的内存非常少,指针允许执行字符串,数组和参数传递。
这是白皮书The Java Language Environment的摘录:
2.2.9 No More Pointers
Most studies agree that pointers are one of the primary features that
enable programmers to inject bugs into their code. Given that
structures are gone, and arrays and strings are objects, the need for
pointers to these constructs goes away. Thus, Java has no pointer data
types. Any task that would require arrays, structures, and pointers in
C can be more easily and reliably performed by declaring objects and
arrays of objects. Instead of complex pointer manipulation on array
pointers, you access arrays by their arithmetic indices. The Java
run-time system checks all array indexing to ensure indices are within
the bounds of the array.
由于指针不正确,你不再有悬空指针和内存垃圾,因为Java中没有指针。