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

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

问题描述

为什么我会收到一个名为 NullPointerException 如果在 Java 中没有指针这样的概念?

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

推荐答案

是的,这是我在学习 Java LOL 时学到的第一个烦人的事情之一.正如 paxdiablo 提到的那样,它确实应该被称为 NullReferenceException、NoObjectException 或 DereferenceException.引用甚至不必在内部表示为指针,您不必关心.包括 Sun 在内的大多数 VM 使用句柄,而不是指针.句柄是指向指针的指针,所以谁知道他们是如何想到使用它的呢?"哦,微软的 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天全站免登陆