aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Generic method doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Generic method doubt" Watch "Generic method doubt" New topic
Author

Generic method doubt

Kedar Pethe
Ranch Hand

Joined: Jul 17, 2012
Posts: 39
Why doesn't the following code compile?


What is wrong with <T extends A> ??
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1031
    
    5



Look at your method signature above and then look at what you are attempting to pass to the go method:



Notice the type for variable l?
Gaurangkumar Khalasi
Ranch Hand

Joined: Jun 02, 2012
Posts: 187
Try out with
instead of
And try to figure out your problem!!!
Kedar Pethe
Ranch Hand

Joined: Jul 17, 2012
Posts: 39
Gaurangkumar Khalasi wrote:Try out with
instead of
And try to figure out your problem!!!


Got it! Thanks gaurang!!
Kedar Pethe
Ranch Hand

Joined: Jul 17, 2012
Posts: 39
James Boswell wrote:

Look at your method signature above and then look at what you are attempting to pass to the go method:



Notice the type for variable l?


Understood.. i should have passed the instance variable of anything that extends A, instead!!
James Boswell
Bartender

Joined: Nov 09, 2011
Posts: 1031
    
    5

No, you are passing a List<T> but the method is expecting T.
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9622
    
    2

James Boswell wrote:No, you are passing a List<T> but the method is expecting T.


And that was exactly what the compiler told you. Have a look at the following page for a much detailed explanation on Generics. Worth the read!

http://www.angelikalanger.com/GenericsFAQ/JavaGenericsFAQ.html


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
 
 
subject: Generic method doubt