1

Is it possible to create a List storing elements, which are objects of class of another object? What I mean is: is it possible to make something like that, but with successful compilation?

private SomeRow row = getRow();  // method getRow returns 
                                 // different classes, which extends SomeRow

List<row.class> rows;  // how is it possible to make something like that?

The problem is that in Selenium WebDriver, which I am using, it is impossible to use wildcards, so it is forbidden to do like this List<? extends SomeRow>.

Does anybody have some ideas how to do this? Or tell me if it is impossible at all, please.

K. Khanda
  • 344
  • 3
  • 11
  • He wants subclasses as well; `List` is more restrictive than `List extends SomeRow>`. – Vivin Paliath Apr 21 '17 at 08:59
  • `row.class` is not giving you a type but a static instance representing the class. So you can't define a `List>` to add some instance of `T` in it. – AxelH Apr 21 '17 at 09:55

1 Answers1

1

Hmm, not sure if this answer your question, how about

List <Object> rows;

then you could cast into appropriate class later using if , probably checking instanceOf the element

adee alamsz
  • 343
  • 2
  • 6