This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

K&B Chapter 3 Question 7

 
Aj Jaro
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can you have access to the private member of the Suits enum on line 13?


Thank you in advance for helping clear this up.
 
Achilleas Achix
Ranch Hand
Posts: 123
BSD Java Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aj Jaro wrote:How can you have access to the private member of the Suits enum on line 13?


Thank you in advance for helping clear this up.


Yes because it is an inner enum.
This, OTOH

would produce a compiler error.
 
Aj Jaro
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, perfect. That was something I should have known. Thank you.
 
Robin John
Ranch Hand
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a small correction... not related to the question...

does this statement print anything meaningful ?





shouldn't it be like ->

 
Aj Jaro
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are right, that it doesn't print anything meaningful, but that was part of the difficulty with choosing the proper answers as well. The available answers were as follows:

Which are true? (Choose all that apply)
A. The output could contain 30
B. The output could contain @bf73fa
C. The output could contain DIAMONDS
D. Compilation fails due to an error on line 6
E. Compilation fails due to an error on line 7
F. Compilation fails due to an error on line 8
and so on

The correct answers were A and B because of how some of the output was unpredictable like you mentioned. You are also correct in stating that using Arrays.asList() will print valuable output as opposed to Suits.values()
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic