Search code examples
javaseleniumreflectioncollectionsdynamic-binding

Place object class instead of generic type


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.


Solution

  • 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