Question

I have a generic dao interface implemented like this:

public interface GenericDao<T extends AbstractEntity> 

and AbstractHibernateDao class:

public abstract class AbstractHibernateDao<T extends AbstractEntity> implements GenericDao<T> 

I'm trying to make generic table model like this:

public class EntityTableModel extends DefaultTableModel {

private GenericDao<AbstractEntity> dao;

public EntityTableModel(GenericDao<AbstractEntity> dao, String[] columnLabels) {
    super(columnLabels, 0);
    this.dao = dao;
}

The way I tried to pass a parameter looks like this:

table.setModel(new EntityTableModel(new SomeEntityHibernateDao(),columns));enter code here

And code for SomeEntityHibernateDao looks like this:

public class SomeEntityHibernateDao extends AbstractHibernateDao<SomeEntity> implements
    SomeEntityDao

SomeEntity extends AbstractEntity and SomeEntityDao is interface which extends GenericDao interface.

Can somebody explain to me why this isn't working? Any help would be really appreciated.

Was it helpful?

Solution

GenericDao<SomeSpecificEntity> is not the same as GenericDao<AbstractEntity>.

Instead, you should allow subclasses:

GenericDao<? extends AbstractEntity> 

You will not be able to call any methods on it that accept T as a parameter, since you don't know what T is.

Alternatively, you could make the entire TableModel class generic, and accept a GenericDao<T>.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top