• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Generic types on methods and classes  RSS feed

 
Ranch Hand
Posts: 430
Android Debian VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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 Debian VI Editor
  • Mark post as helpful
  • send pies
  • 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
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Surely you cannot have:



Compiler will moan that T is not defined?
 
O. Ziggy
Ranch Hand
Posts: 430
Android Debian VI Editor
  • Mark post as helpful
  • send pies
  • 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
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • 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
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • 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 Debian VI Editor
  • Mark post as helpful
  • send pies
  • 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..
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!