I currently am writing this function:
public WebElementList findWebElementList(final By by){
return new WebElementList((List<WebElement>) Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class<?>[] { List.class }, new InvocationHandler() {
// Lazy initialized instance of WebElement
private List<WebElement> webElements;
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
if (webElements == null) {
webElements = findElements(by);
}
return method.invoke(webElements, args);
}
}), driver);
}
It is throwing an unchecked cast from Object to List. I have used a proxy around WebElement, and it doesn't...so I believe that is caused by List being a generics class.
Is there any way for me to have a proxy around a List, and not get that unchecked cast warning?