Re: Doubt on Generics and Interfaces
Vinicius Cubas Brand wrote:
Hello. I have implemented an interface "ComboItem" and a class
implementing this interface, named "PortadorDireito". This class
"PortadorDireito" is abstract and is extended by the class
"Operador".
In another class, I have a method that receives a list of ComboItem,
like this:
import java.util.List;
class TesteAction {
public void teste (String x, String y, List<ComboItem> options,
ComboItem default) {
...
}
}
Then, when using this method TesteAction.teste(), I am passing a
List<Operador> as parameter, like this:
testeAction x = new TesteAction();
x.teste(String a, String b, List<Operador> c, Operador d)
The compiler is not accepting, so I must have done something wrong
with generics, or forgot to implement something. Do you have hints on
what I am doing wrong?
also the following gives error also, but different:
x.teste(String a, String b, List<Operador> c, null)
Below follow the error for the first case:
Caused by: java.lang.Error: Unresolved compilation problem:
The method adicionarFiltroCombo(String, String, List, ComboItem,
String, boolean) in the type RelatorioAction is not applicable for the
arguments (String, String, List, Operador, String, boolean)
and for the second case:
Caused by: java.lang.Error: Unresolved compilation problem:
The method adicionarFiltroCombo(String, String, List, ComboItem,
String, boolean) in the type RelatorioAction is not applicable for the
arguments (String, String, List, null, String, boolean)
Thank you.
If you need to take a list of things that extends ComboItem, then you
should accept List<? extends ComboItem> instead of just List<ComboItem>
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>