In the below code, the hash code is always same. Why is it like that?
Code:
public class BooleanClass {
public static void main(String[] args) {
Boolean b1 = new Boolean(true);
Boolean b2 = new Boolean(false);
Boolean b3 = new Boolean(true);
Boolean b4 = new Boolean(false);
Boolean b5 = new Boolean(false);
Boolean b6 = new Boolean(true);
System.out.println(b1.hashCode());
System.out.println(b2.hashCode());
System.out.println(b3.hashCode());
System.out.println(b4.hashCode());
System.out.println(b5.hashCode());
System.out.println(b6.hashCode());
}
}
Output:
1231
1237
1231
1237
1237
1231
Always the same numbers 1231
and 1237
are printed. Any reason?