Auto boxing and boxing classes of wrappers

in wrapper classes, we have two types of methods parseXxx () and valueOf () in each wrapper class for mutual conversion between primitive and wrapper objects. As a result, java 1.5 introduced automatic boxing and boxing. Therefore, they did not condemn these methods.

+3
source share
4 answers

Since Autoboxing and Auto Unboxing are just compile-time functions. Try writing something like this in the source file, and then look at the decompiled code:

Integer i = 10;

Decompiled code:

Integer i = Integer.valueOf(10);

Similarly

int i = new Integer(100);

when decompiling you will get the following:

int i = (new Integer(100)).intValue();

Thus, the JVM still relies heavily on these methods at runtime, although it masquerades when writing code.

+6
source

, parseXxx() ; String . valueOf(), , - -, , . Java valueOf(), , .

+2


1. , ( , , / ).
2. , ?

0

Since the command line arguments are treated as a String Array, but on the condition that you expect a command line argument that is different from the String data type (it can be primitives), i.e. boolean, int, byte, short, long, float, double, char, than you need to parse the argument in what your program expects, and here you use the parseXXX () methods to be precise, the parseXXX method takes a String argument and returns the corresponding data type that you are trying to parse.

0
source

All Articles