Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why doesnt this compile?

 
Ankur kothari
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


return type is list..and am returning an arraylist?

this is from inquistion? is it related to <String>
 
rohan yadav
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
List<> is superclass of ArrayList<>, hence we can return ArrayList<>. So thats why it compiles
 
Ankur kothari
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it doesnt compile.......
 
rohan yadav
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
may be this will help you

 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code does not compile because the expected return type is List<T>, but you are returning List<String>.

You cannot guarantee that List<String> is of type List<T> at compile time, therefore, the compiler generates an error.
 
Ankur kothari
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rohan and Edwin....understood the concept
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic