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:
- The line
drivers = new AndroidDriver[5] ;
generates a warning because I don't give the generic type. How can I fix it? - 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.