I'm currently learning java, and I encountered a problem with generics that I can not solve.
So I have this class:
public class EntityRepository <Entidade extends Entity>{ "code" }
with this method:
public Long create(Entidade ent) {
ent.setId(this.nextId());
this.m1.put(ent.getId(), ent);
return ent.getId();
}
and now i have another method in another class like this:
public static void subMenu(EntityRepository<? extends Entity> repository, String entidade)
which has this code:
Entity item = new Entity();
if(entidade.equals("produto")){
item = new Product();
}
else if(entidade.equals("prateleira")){
item = new Shelf();
}
repository.create(item);
repository.printList(entidade);
so basically when String 'entidade' is equal to strings "produto" or "prateleira" it is supose to call the 'create' method from the first class I mentioned above but with either a 'Product' or a 'Shelf' as a parameter. (which are objects that extend to Entity)
my problem is that is that has this error:
"The method create(capture#1-of ? extends Entity) in the type EntityRepository is not applicable for the arguments (Entity)"
and i cant seem to understand why nor can i find any clues around the web...
can some one help me? thanks!