So I have this code:
public static void main( String[] args )
{
int i = 3;
int j = new Integer(5);
JOptionPane.showMessageDialog(null, Boolean.toString(j.equals(5)));
}
It should open a message dialog with the text "true". The problem is it gives a compiler error saying that I can't invoke a method on the primitive type int. Why is this happening?
Casting ((Integer) j).equals(5)
works as expected. I just don't understand why the object j
is turning into a primitive type.