Machine-translated by Google. Questions are authored in English.
Top

Discussion

Consider what happens when an int is added to a List<Integer>. Which statement is correct?

  • A.It is boxed.
  • B.It is boxed to an Integer automatically.
  • C.The compiler rejects it.
  • D.It is stored as a primitive.

Answer: B

Autoboxing inserts the conversion for you in both directions, so the code reads as if the list held ints. The costs to remember are the allocation, and that unboxing a null element throws NullPointerException rather than yielding zero.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.