为什么Java有“NullPointerException”?什么时候Java中没有指针? [英] Why does Java have a "NullPointerException" when there are no pointers in Java?

查看:213
本文介绍了为什么Java有“NullPointerException”?什么时候Java中没有指针?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我会收到名为 <$的异常c $ c> NullPointerException 如果在Java中没有指针这样的概念?

Why do I get an exception called NullPointerException if in Java there is no such concept as a pointer?

推荐答案

是的,这是我在学习Java LOL时学到的第一个烦人的事情之一。
它应该被称为NullReferenceException,NoObjectException或DereferenceException,如paxdiablo所述。
引用甚至不必在内部表示为指针,你不必关心。
大多数虚拟机包括Sun的使用句柄,而不是指针。句柄是一个指针指针,所以谁知道他们如何使用它?
哦,微软的Java VM实际上确实使用了指针而不是句柄,所以请记住。

Yes this is one of the first annoying things I learned when learning Java LOL. It really should be called NullReferenceException, NoObjectException or DereferenceException as paxdiablo mentioned. References don't even have to represented internally as pointers and you shouldn't have to care. "Most VMs including Sun's use handles, not pointers. A handle is a pointer to a pointer so who knows how they came up with using that?" Oh Microsoft's Java VM actually does use pointers rather than handles so go figure.

这篇关于为什么Java有“NullPointerException”?什么时候Java中没有指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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