5
List<? extends List<? extends ObservationInteger>>

Just to give you a background which probably has nothing to do with the question. Trying to use the JAHMM library to build and score HMM's.

One of the parameters to the functions mentions the above as the datatype and I have no idea what it means.

From what I understand with help from a friend List<? extends ObservationInteger> means a List of instances of any classes extending "ObservationInteger" which is a valid class in the library.

It is the outer List<? extends List<?... that is confusing me.

Can someone throw some light on this?

Paul Bellora
  • 54,340
  • 18
  • 130
  • 181
Ashwin
  • 1,190
  • 2
  • 10
  • 30
  • 1
    Basically it's a `List` of anything that extends a `List` which contains anything that extends `ObservationInteger`. While not exactly the same, it might be easier to look at it like `List>` (this is much more restrictive version, but might help you understand what it's trying to do) – MadProgrammer Oct 28 '13 at 05:01
  • So does it mean that I have suppose a Class A which is extending ObservationInteger and then I have another class Class B which extends List and I'm storing instances of Class A in a Class B instance ? – Ashwin Oct 28 '13 at 05:08
  • 1
    And then all that in another list, but yes, you have a `List` of `List`s which contain objects that extend from `ObservationInteger`. If I recall correctly, it also makes it impossible to add any new items to the list, but that's a side effect in this case ;) – MadProgrammer Oct 28 '13 at 05:11
  • So instead of Class A I can just use instances of the ObservationInteger Class? – Ashwin Oct 28 '13 at 05:15
  • 1
    Yes, assuming you can instantiate it. If you were to do something like `list.get(0).get(0)` (and assuming that it had valid values) it would return an `ObservationInteger`, because that's the most that it can gurentee... – MadProgrammer Oct 28 '13 at 05:17
  • Thank you so much for bearing with my questions. I found your comments very helpful.I will go ahead and try it out. – Ashwin Oct 28 '13 at 05:19
  • possible duplicate of [What are multi-level wild cards? Confusion in syntax](http://stackoverflow.com/questions/18194956/what-are-multi-level-wild-cards-confusion-in-syntax) – Rohit Jain Oct 28 '13 at 05:50

4 Answers4

3

List<? extends List... means that it can be List of any Collections implementing List interface.

List<List<? extends ObservationInteger>> list = new ArrayList<List<ObservationInteger>>(); - compiler error because without ? extends compiler requires exact match:

List<List<? ObservationInteger>> list = new ArrayList<List<? extends ObservationInteger>>(); - OK

but this looks better

List<? extends List<? ObservationInteger>> list = new ArrayList<List<ObservationInteger>>(); - OK

Evgeniy Dorofeev
  • 133,369
  • 30
  • 199
  • 275
1

It means any Class implementing List Interface with instances of any Class implementing List Interface with instances of any classes extending "ObservationInteger"

Pratik Tari
  • 198
  • 1
  • 8
1

It is a List of Objects, which are all instances of a class that extends List.Because those objects are instances of Lists, each of them happens to contain a certain amount of Objects, which are all instances of a class that extends ObservationInteger.

qwertyuiop5040
  • 417
  • 3
  • 15
1

It's a list of lists of things. Visualize it as a two-dimensional structure (rows & columns).

The ? extends means it is also valid for any subtypes of List and any subtypes of ObservationInteger.

Boann
  • 48,794
  • 16
  • 117
  • 146