Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Study Guide 6 -- Chapter2 Self Test Question 15 on page 181.

 
Graciela Zaffarana
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Greatly appreciate your input.

Best,

Wanna be a "Java compiler thinking machine"
 
Neha Daga
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should post code as everyone may not be having book with them.
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Graciela Zaffarana
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey! but at least in question 9 of Chapter 1 "myGold" is boxed; in question 15 of Chapter 2 it is not. Okay, okay ... I will hang in there one chapter longer to be enlightened.

Here is the code: ( I hope that I am posting it right -- with line numbers --- when I click the <submit > ; otherwise, tell me how, I will know better next time around. Cheers!

 
Graciela Zaffarana
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I posted the code with my changes. Here is the original as showing on the Self Test question:

 
Ankit Garg
Sheriff
Posts: 9519
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Neha Daga
Ranch Hand
Posts: 504
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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? ---


yes you should always stick to it.
 
Graciela Zaffarana
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay. Thank you. Til next round ...

G.Z.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic