Study Guide 6 -- Chapter2 Self Test Question 15 on page 181.
Hello Fellas ...
(1) It is clear that the code on question 15 compiles; I verified that. But, does int 7 in line 12 --- "sifter(7)" get boxed by the compiler behind the scenes? Really? Do I have to read more through the book to get an answer on how the compiler does it, or can you tell me? Without having to declare it as: new Integer(7)? Please, comment. ( It goes without saying that I had chosen Compilation fails because I thought that 7 was not an Object but primitive data. )
(2) Also, It occurred to me to comment out the version of method sifter that expects an Object to see if array "aa" got routed to version of sifter with argument equal to A... a2, and indeed it did! So, is there more than one answer to this question? or should we consider the comment " In general, overloaded var-args methods are chosen last." as the law of the land? ---
NOTE: In the process of recompiling the code after commenting out line 18 sifter(Object o) , I had to also comment out line 12 sifter(7) --- Interestingly enough, the compiler error sort of directed me to think that it views 7 (like I do) as a primitive integer and not as an object of type Integer. Compiler error message is somewhat misleading in my view.
1) I made that mistake in chapter 1 selftest question number 9 . But you'll read all about boxing and related stuff in the next chapter.
2) In chapters to come (don't know which one) the order in which methods are called will be explained.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Okay I'm confused. Can you post the code of the book and the doubts that you have together. I can't understand which is the actual code and the questions in your mind as its distributed here and there...
yes on line 12 in sifter(7); 7 is automatically boxed by compiler and the second observation is correct that when you comment out the sifter(object o) method it will go to var args version but there is only one answer to the question as object version is not commented and var args is always chosen the last so object version will be chosen.
or should we consider the comment " In general, overloaded var-args methods are chosen last." as the law of the land? ---