For autoboxing part 2 here is a comment from Guadalupe from a question asked in the Help section:
" The problem lies in that after the first boolean check, there is the number 100 in 'int' form. This forces the compiler to start the process of boxing so when the second boolean check is performed what is happening behind the scenes is that it calls the Integer constructor ( new Integer( ) )and passes the result of the second to as an argument. If you pass null to this constructor then a null pointer exception is thrown. So, the line:
return first ? 100 : second ? 200 : null;
processes like this:
#1 it checks the valuation of 'first', which in this task is just a boolean but could be a boolean expression. It then moves to the result if true and result if false.
#2 Because the result if true is a primitive, the auto-boxing feature kicks in and the constructor for Integer is called
#3 if the result is true the 100 is passed to the constructor and all is good
#4 if the result is false then it checks the second expression and passes either of the results to the Integer constructor
#5 if true then 200 is passed in and all is good
#6 if false then null is passed in and the exception is thrown
You will find that if you have just a single expression, then null value can be assigned. So the key problem in the above code is when the auto-boxing feature occurs. "
So think about what type of element you would need so that null is accepted.
GO TO FULL VERSION