• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generics question from K&B self test

 
madhu v pe
Ranch Hand
Posts: 100
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am having a doubt in the answer given for this question.


Please have a look into the Bolde text in the answer
my question is the return type cannot be ArrayList?

Please anyone can help me in explaining this?

Thanks in advance
 
Abdullah Mamun
Ranch Hand
Posts: 99
Eclipse IDE Mac
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public static <E extends Number> List<E> process(List<E> nums)
A programmer wants to use this method like this:
// INSERT DECLARATIONS HERE
output = process(input);


The method process() returns a List<E> and it will be assigned to output variable. So if output is declared as an ArrayList then you cannot assign the returned value of process() into it, since List cannot be assigned to ArrayList.

Hope you got the point
 
madhu v pe
Ranch Hand
Posts: 100
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh its simple thanks Moon
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic