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
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply 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
Ranch Hand

Joined: Nov 09, 2011
Posts: 657
    
    2



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: 186
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
Ranch Hand

Joined: Nov 09, 2011
Posts: 657
    
    2

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

Joined: Sep 26, 2006
Posts: 8795

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, SCBCD Hints - Demnachst, SCDJWS - Auch Demnachst
Did a rm -R / to find out that I lost my entire Linux installation!
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Generic method doubt
 
Similar Threads
Difference between ArrayList and LinkedList?
Question on generic method
Collections -super is not working
why l.add() method is not working in this context?
Comparator sort issue