I have this code:
package tests;
import java.util.Hashtable;
public class Tests {
public static void main(String[] args) {
Hashtable
A way to understand it is when Boolean.valueOf(null)
is invoked, java is precisely being told to evaluate null.
However, when Boolean.valueOf(modifiedItems.get("item1"))
is invoked, java is told to obtain a value from the HashTable of object type Boolean, but it doesn't find the type Boolean it finds a dead end instead (null) even though it expected Boolean. The NullPointerException exception is thrown because the creators of this part of java decided this situation is an instance of something in the program going wrong that needs the programmer's attention. (Something unintended happened.)
In this case it is more the difference between deliberately declaring that you intended the null to be there, and java finding a missing reference to an object (null) where an object was intended to be found.
See more information about NullPointerException in this answer: https://stackoverflow.com/a/25721181/4425643