There's the Main class and 2 example classes. One extends HashMap.
The Main:
public class Main {
public static void main(String[] args) {
System.out.println("Positive:");
PositiveExample positiveExample = new PositiveExample();
positiveExample.printThis();
System.out.println("Negative:");
NegativeExample negativeExample = new NegativeExample();
negativeExample.printThis();
}
}
The standard one:
public class PositiveExample {
void printThis() {
System.out.println(this);
System.out.println(this == null);
}
}
And the HashMap based one.
import java.util.HashMap;
public class NegativeExample extends HashMap {
void printThis() {
System.out.println(this);
System.out.println(this == null);
}
}
Now take a look at the console output:
Positive:
PositiveExample@2a139a55
false
Negative:
{}
false
And notice the empty {}. As opposed to PositiveExample@2a139a55 from the standard class' output.
The HashMap based class output says this is not null, but that's how it behaves, doesn't it. Check it for yourselfs.
I'm on Java build 1.8.0_60-b27, Ubuntu 14.04 64 bit.