0

I'm using a method:

public List<IRecord> combineTypes(List<IRecord>)

Which will take the required values from the IRecord objects and combine like values, updating and returning the updated list.

However, IRecord is an interface. I'm attempting to call the combineTypes() method on passing in a list of an object that implements the IRecord interface:

For example, the CoverageRecord class implements IRecord

and I am trying to call

combineTypes(data)

where data is a List<CoverageRecord>

But my compiler is throwing an error, saying I am passing in an invalid argument.

Is there a workaround or something I am missing? I feel like I'm just brain-farting.

zomgcopters
  • 79
  • 1
  • 1
  • 9
  • Is `List` a typo for `List`? – AntonH May 12 '14 at 19:59
  • 2
    http://docs.oracle.com/javase/tutorial/java/generics/subtyping.html – Alexis C. May 12 '14 at 19:59
  • @AntonH yes it is, I'll fix it for clarity. Also forgot to mention that the combineTypes returns a List – zomgcopters May 12 '14 at 20:02
  • @ZouZou thank you, reading that over led me to a fix! I knew I was forgetting something relatively simple. – zomgcopters May 12 '14 at 20:07
  • Wow, it seems that [I recently got some superpowers](http://meta.stackoverflow.com/questions/254589/when-did-i-get-superpowers) and now can close questions with tag I have gold badge all by myself, without waiting for approval of other users with moderation privileges. If you think your question is not duplicate feel free to inform me about it and I will reopen it for you. – Pshemo May 12 '14 at 20:08
  • @Pshemo You're a superhero ;-) – Alexis C. May 12 '14 at 20:08
  • @Pshemo No, it very well could be, I just didn't know how to phrase it better (long day) and didn't see a similar question after looking for a little bit. Zouzou led me to the documentation I needed, so keep it closed – zomgcopters May 12 '14 at 20:10
  • 2
    @zomgcopters Sorry, actually you should start by reading this: http://docs.oracle.com/javase/tutorial/java/generics/upperBounded.html :) That will solve the issue you are facing. So to answer your question `combineTypes(List extends IRecord> list)` should do the trick. – Alexis C. May 12 '14 at 20:12
  • @ZouZou Thanks! Everything is working great now! – zomgcopters May 12 '14 at 20:16

0 Answers0