Use Boolean The valueof () method vs (or Java 1.5 autoboxing) creates a Boolean object
•
Java
Boolean. Valueof() and Java 1.5 auto@R_750_2419 @A better approach between ing is to create Boolean values from Boolean values. Why?
Solution
Boolean auto boxing is transparently converted to Boolean by the compiler valueOf():
boolean b = true; Boolean bb = b;
Translated into:
iconst_1 istore_1 //b = 1 (true) iload_1 //b invokestatic #2; //Method java/lang/Boolean.valueOf:(Z)Ljava/lang/Boolean; astore_2 //bb = Boolean.valueOf(b)
Use whatever you think is more useful and readable Due to the use of Boolean Valueof () doesn't give you anything except extra input. You should aim at automatic packing
When you consider the opposite transformation, the situation becomes complicated - from Boolean to Boolean This time, the compiler will call Boolean. Net transparently Booleanvalue(), in theory, will lead to NullPointerException
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码