Java: casting Object to int

I found something odd when writing a Java program yesterday.

In a JTable you have an int to display (the amount ordered e.g.), but when getting the value of a cell you obviously get an Object, not an int.

In order to get the Object into an int variable, you might experience this issue:

//this does not works (obviously)
int element = this.jTableProducts.getElementAt(4, 4);

//this works! (obviously, Integer is a subclass of Object)
Integer element = (Integer)this.jTableProducts.getElementAt(4, 4);

//this odly enough does not works
int element = (int)this.jTableProducts.getElementAt(4, 4);

//but this works
int element = (Integer)this.jTableProducts.getElementAt(4, 4);

This is due the autoboxing of Integer to int (and vice versa).