Why does Java have a “NullPointerException” when there are no pointers in Java?

前端 未结 6 1429
不思量自难忘°
不思量自难忘° 2020-12-06 01:23

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

6条回答
  •  暖寄归人
    2020-12-06 01:41

    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.

提交回复
热议问题