Any way to see HashCode of primitive types?
hashcode, java
Solution
You cannot invoke methods on primitive types.
`n` is declared as `int`. It does not have methods.
It does not make sense to think like
If i still need to see hascode for int in below program
You could create an `Integer` object and get its `hashCode()`
Integer.valueOf(n).hashCode()
`Integer#hashCode()` is implemented as
public int hashCode() {
return value;
}
where `value` is the `int` value it's wrapping.
Does this means that if int n = 10 then its HashCode will also be 10??
The `int` doesn't have a hashcode. Its `Integer` wrapper will however have the value of the `int` it's wrapping.
Problem
Mugging up basic D.S....I read that, no `hashCode()` method for primitive type `int` is available and if called on `int`, it will throw error error: int cannot be dereferenced Does this means that if `int n = 10` then its `HashCode` will also be 10?? If i still need to see hascode for `int` in below program, is there a method to see it, like `Integer` `Wrapper`??? ``` public static void main(String []args){ String me = "hello"; int n = 10; int h1 = me.hashCode(); int h2 = n.hashCode(); System.out.println(h1); System.out.println(h2); } ```