I am getting the following error:
Bound mismatch: The generic method constructPage(WebDriver, int, Class) of type
Page is not applicab
If you still wish HomePage
to extend SecuredPage
with the presence of Bounded Generics, please pass the 'Generic Substitution' till HomePage.
Do not substitute Generic at SecuredPage
, instead make SecuredPage
as
public class SecuredPage<T extends Page<T>> extends Page<T> {
}
and while creating HomePage
, declare the value for the generic like this,
public class HomePage extends SecuredPage<HomePage> {
}
This should essentially solve the error
Calling login(user, SecuredPage.class)
works, but login(user, HomePage.class)
does not. The reason is: type parameter T
in SecuredPage
is SecuredPage
. HomePage
is a subclass of SecuredPage
, so the T
type parameter of HomePage
is SecuredPage
as well.
Now, you call login
with a Page<HomePage>
. But such a class does not exist. HomePage
is a subclass of Page<SecuredPage>
.
For the purposes of your constructPage
method, you could just use
protected static final <T extends Page<?>> T constructPage(...)
{
Page<?> p = null;
//...
}
If you any one still face the same error change JDK 1.8 or latest version in compiler level from Window > Preferences > Java > Compiler > "Compiler Compilation level" -> 1.8
The problem is that HomePage
is a Page<SecuredPage>
and not a Page<HomePage>
. The login
method would return a Page<HomePage>
from its generic signature.
You must make the generic parameter of HomePage
related to itself, not SecuredPage
. This will resolve the compiler error. Keep SecuredPage
generic, but make sure its bound extends SecuredPage<T>
. Then assign HomePage
itself for the generic parameter T
in HomePage
.
class SecuredPage<T extends SecuredPage<T>> extends Page<T> {
...
}
class HomePage extends SecuredPage<HomePage> {
...
}