Most of the time, someone will ask you, do you know what the packaging class is?
or high-end to ask you you know, wrapper type, what is it?
And then you get confused and learn Java a lot of times don't know what it is.
Actually ask your person, may just want to ask you, Java object-oriented you understand how.
In Java many times we say that everything is the object.
But int,double, there are a few exceptions to tell you that he is not the object.
But most of the time we need objects, not int, but we need objects like int.
For example, you need to use int in a list, but list can only put objects. There are a lot of similar problems.
So Java5 appeared an integer.
This is the legendary packaging class.
So what's the problem with the packaging class?
This time I met a very easy mistake.
list<integer> list = new arraylist<integer> ();
List.add (1);
List.add (2);
List.add (NULL);
for (int i:list)
{
sum + = i;
}
And then it's an error.
This loop uses an int to connect the value, then Java will take advantage of the automatic unpacking function.
Then a lot of people will ask, what is automatic unpacking.
Simply put, Intvalue () is called to convert an integer to an int value.
Then the error is very easy to appear, the empty object is not intvalue this method.
So later, either the value of the time to empty, or use an integer to connect the value, do not lazy with the automatic unpacking function.
Don't tell me you don't know. Wrapper classes in Java, wrapper type, and issues that can easily occur in automatic unpacking