| 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
|
|
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
|
|
|
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!
|
 |
 |
|
|
subject: Generic method doubt
|
|
|