Which is better in terms of performance, implicit (automatic) decompression, or explicit decompression?

Put it in code - which has better performance (if there is a difference at all)?

Considering 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 that:

public void handleCustomer(Customer customer)
{
    if (customer.isVIP().booleanValue()) // Explicit unboxing
    {
        handleNow(customer);
    }
    else
    {  
        sayHandlingNowButQueueForTomorrow(customer);
    }
}
+1
source share
4 answers

There is no difference between the two, you can check in the bytecode:

public class ImplicitTest {
    public static void main(String[] args) {
        Boolean b = true; 
        boolean i = b;
        boolean e = b.booleanValue();
    }
}

This will compile for:

javap -c ImplicitTest

Compiled from "ImplicitTest.java"
public class ImplicitTest extends java.lang.Object{
public ImplicitTest();
  Code:
   0:   aload_0
   1:   invokespecial   #1; //Method java/lang/Object."<init>":()V
   4:   return

public static void main(java.lang.String[]);
  Code:
   0:   iconst_1
   1:   invokestatic    #2; //Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean;
   4:   astore_1
   5:   aload_1
   6:   invokevirtual   #3; //Method java/lang/Boolean.booleanValue:()Z
   9:   istore_2
   10:  aload_1
   11:  invokevirtual   #3; //Method java/lang/Boolean.booleanValue:()Z
   14:  istore_3
   15:  return

}

As you can see, lines 5,6,9 (implicit) are the same as 10, 11, 14 (explicit).

+10
source

, - . - Java . . , unboxing , , .

+7

, .

, , , . , , , - , . , , , (, ).

, . . , , .

, JVM , . , , . JVM , , .

, , : , , , .. .

+3

VIP , Boolean Boolean?

0
source

All Articles