• 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

Generic types on methods and classes

 
Ranch Hand
Posts: 430
Android VI Editor Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


The above syntax has confused me slightly as i never saw that syntax before

- What is the difference between <V extends B> and <? extends B>
- Is it legal to have the type defined at both the class level and method level. I thought you can only do one of the following but not both.

 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a question from the self assessment 2 of the K & B Practice exam book. I could not figure this one out even after looking at the answer. Would be nice if somebody could explain it. I found the self assessments quite frustrating. I did quite well in the first one and then in the book it says 'Now for the bad news ... We picked 14 of the easiest questions'. In the second self assessment I did pretty badly the book saying 'You need a LOT more studying' (after reading the K & B study guide twice ).

John
 
O. Ziggy
Ranch Hand
Posts: 430
Android VI Editor Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

John Stark wrote:This is a question from the self assessment 2 of the K & B Practice exam book. I could not figure this one out even after looking at the answer. Would be nice if somebody could explain it. I found the self assessments quite frustrating. I did quite well in the first one and then in the book it says 'Now for the bad news ... We picked 14 of the easiest questions'. In the second self assessment I did pretty badly the book saying 'You need a LOT more studying' (after reading the K & B study guide twice ).

John



This is exactly how i felt! i got 11 out of 14 for the first assessment but then i got 4 out of 14 on the second assessment.

I think the questions are unecessarily difficult for the required level to pass. It is probably a good thing as it makes you put a lot of thought on the question but if you are only limited to one or two hours a day for the revision it is not very helpful.

I wonder if it is better to do few difficult questions or lots of intermediate level questions..
 
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Surely you cannot have:



Compiler will moan that T is not defined?
 
O. Ziggy
Ranch Hand
Posts: 430
Android VI Editor Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

James Boswell wrote:Surely you cannot have:



Compiler will moan that T is not defined?



I was referring to declaring a generic method on a class that is not generic. Like this one.

 
Ranch Hand
Posts: 58
Eclipse IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

James Boswell wrote:Surely you cannot have:



Compiler will moan that T is not defined?



Compiler here complains because return type of the method is missing. Just make it '<T> void method(){}' and it will be a generic method.
 
Sebanti Sanyal
Ranch Hand
Posts: 58
Eclipse IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is perfectly legal to have something like this.


What is the difference between <V extends B> and <? extends B>



Syntax like <? extends B> is used for reference variable declaration, method arguments and return type.
While defining generic class and methods, you can't use '?', have to go for something like <V extends B>.
 
O. Ziggy
Ranch Hand
Posts: 430
Android VI Editor Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sebanti Sanyal wrote:It is perfectly legal to have something like this.


What is the difference between <V extends B> and <? extends B>



Syntax like <? extends B> is used for reference variable declaration, method arguments and return type.
While defining generic class and methods, you can't use '?', have to go for something like <V extends B>.



Thanks Sebanti. I wasnt aware of that..
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic