Why comparison of null Boolean variable gives me NPE using == operator but same operator on null String variable do not give NPE.
Snippet:
public static Boolean disableDownloadOnShareURL = null;
public static String hi= null;
public static void main(String[] args)
{
try
{
if(disableDownloadOnShareURL == true)
System.out.println("Boolean Comparison True");
else
System.out.println("Boolean Comparison False");
}
catch(NullPointerException ex)
{
System.out.println("Null Pointer Exception got while comparing Boolean values");
}
try
{
if(hi == "true")
System.out.println("String Comparison True");
else
System.out.println("String Comparison False");
}
catch(NullPointerException ex)
{
System.out.println("Null Pointer Exception got while comparing String values");
}
}
Output:
Null Pointer Exception got while comparing Boolean values
String Comparison False