• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

SCJP Sun Certified Programmer for Java 6 Study Guide by Kathy Sierra & Bert Bates - Page 622

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I'm new to this forum. I'm here since I bought this wonderful book for preparing to my SCJP certification.
But today I stumbled on page 622. I think, here is a mistake.
On page 621 there are 6 lines of code asking to determine, which will compile. My concern is for statment no. 4, which is:
4) List<? extends Dog> cList = new ArrayList<Integer>();
Of course, this will not compile. But, in the explanation on the next page (622), there is written:
"Problem: You cannot assign an Integer list to a reference that takes only a Dog (including any subtypes of Dog, of course)"

And as far as I understood generics by now, the text in braces should be wrong: "(including any subtypes of Dog, of course)"
Shouldn't it be called "(including any SUPER-types of Dog, of course)"?

Am I wrong and if, why?

Thank you in advance and best regards

Karl
 
Greenhorn
Posts: 8
Android Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am also preparing for scjp and if i understand generics so far thn i think what they mean is that cList could be of type Dog or its subtypes and neither can b assigned an Integer list. clist can not be of type super classes of Dog.
 
Karl Dirr
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you. To be more precise, here some code:



I sumbled over the sentence in braces: "(including any subtypes of Dog, of course)".
For my understanding, in the context of the explanation, it is not quit correct.
But this may be a translation issue on my side.
Anyway, the code example above explains what compiles and what do not compile.

Thank you

Karl
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Karl welcome to javaranch.

Please UseCodeTags when you post a source code.

The sentence in the braces is in accordance with the 3rd list in your code
beagleList can point to a List of type Dog or Beagle or any other subtype of Dog...
 
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Karl,

Willkommen bei JavaRanch. (I am studying for the SCJP exam and also German so please correct my grammar.)

The phrase in the parentheses," (including any subtypes of Dog, of course) " refers to the consequence of line #13 below:

I think the author tried to make a simple comment that the reference in List cannot be Dog or subtype of Dog, such as Beagle.
 
Karl Dirr
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you and "Dankeschoen" for your welcome. It's a nice place here.

I tended already to the way, I misunderstood this.
Anyway, more important is, to understand generics in common. And I'm not finished these 2 days yet, for "getting" generics, known as "48 consecutive hours" :-)

I have to give a very high compliment to this wonderfull book.
I started learning Java last July and took my training on the "Sun Web Learning Center", other books, on the web and the Java tutorials from Sun. But all in all I wasn't satisfied. And as I did my first test in preparation to the certification, the result was terrible and disapointing. After that, I was search for a way out, to find the way for understanding Java. And during this search, I found this very very good book from Kathy and Bert. And from this time on, Java is getting more and more understandable for me. Thanks to them!

On April, 8th I will go to Munich to take my exam.

Karl
 
Larry Chung
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree that the SCJP book is a very valuable tool.

You might notice that members in JavaRanch also talk about another tool called ExamLab. It is an SCJP exam simulator consisting of several mock exams with small tutorials. It was developed by one of our fine members of JavaRanch, Devaka Cooray. The simulator can be downloaded from http://examlab.tk/. I have started using it and I have learned a lot. It is free and is very good (Es ist kostenlos und sehr gut).
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi! Karl welcome to java ranch.notice that keyword<? extends dog> which means it can refer to generic type dog and anything that extends dog.if this was<? super dog> then it can refer to generic type dog and anything which is super to dog.
 
Karl Dirr
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you to everybody. I will take the ExamLab into consideration for my next steps. Thank's again.
I have put together some code, demonstrating this issue on generics:



Dankeschön!

Karl

 
reply
    Bookmark Topic Watch Topic
  • New Topic