Usually the compiler generates code to perform boxing and unboxing. But what does the compiler, if the boxed values are not needed? Is the (Oracle standard) compiler smart enough to optimize it away?
Take a look at this method:
public static void requireInRange(int index, Object[] array) {
if(index < 0 || index >= array.length)
throw new IndexOutOfBoundsException();
}
The only relevant information is the array.length, so it would be useless to box each value of an array for example. Like in this code:
int[] anArray = {3, 4, 2};
requireInRange(3, anArray);
Will the compiler actually insert code for boxing each value of the array?