To put it in code – which has better performance (if there is a difference at all)?
Given this:
public class Customer
{
....
public Boolean isVIP(){...}
...
}
Which is faster?
public void handleCustomer(Customer customer)
{
if (customer.isVIP()) // Auto Unboxing
{
handleNow(customer);
}
else
{
sayHandlingNowButQueueForTomorrow(customer);
}
}
or this:
public void handleCustomer(Customer customer)
{
if (customer.isVIP().booleanValue()) // Explicit unboxing
{
handleNow(customer);
}
else
{
sayHandlingNowButQueueForTomorrow(customer);
}
}
No difference between them, you can verify it in the bytecode:
Run
javapto see what it compiles to:Here is the output:
As you can see – lines 5,6,9 (implicit) are the same as 10, 11, 14 (explicit).