0

I need to create an array of AndroidDriver, which is public class AndroidDriver <T extends WebElement>. So I try to do the following thing:

AndroidDriver<AndroidElement> drivers = null ;
//...
drivers = new AndroidDriver[5] ;
for (int i=0 ; i < drivers.length ; i++)
    drivers[i] = new AndroidDriver<>(/*Some arguments...*/) ;

I have two questions:

  1. The line drivers = new AndroidDriver[5] ; generates a warning because I don't give the generic type. How can I fix it?
  2. When I took a look online, I saw that most of the time developers don't bother to specify the generic type, so they simply use AndroidDriver drivers = null ;. It generates a warning, but it seems to run fine. Don't we need to specify the generic type?

Thanks for you help!

[Edit] I can however create a list without any warning: List<AndroidDriver<AndroidElement>> list = new ArrayList<>(5). Why does it compile without a warning? But when I want to get the array using (AndroidDriver<AndroidElement>[])list.toArray(), then I get the warning again.

FiReTiTi
  • 4,748
  • 11
  • 22
  • 47
  • http://stackoverflow.com/questions/529085/how-to-create-a-generic-array-in-java... Check this out – Grasshopper Oct 17 '16 at 04:33
  • Thanks for the link, but contrary to this post, I have to create an array of a class that I didn't create. I can only instantiate it. I have added the class declaration in my post – FiReTiTi Oct 17 '16 at 05:15

0 Answers0