0
public class JobAssetService extends GenericService<JobAssetService, JobAsset, JobAssetDao> {

}

一般的な save() 機能をサービス レイヤーに提供しようとしていますが、 に渡すものが気に入らないようですdao.save()。これはうまくいくようです...

互換性のない型が必要: M 見つかった: java.lang.object

public class GenericService<T, M, Dao extends GenericDao> {

    protected Dao dao;
    protected EntityManager em;

    public GenericService() {

    }

    //map the dao/entity manager when instantiated
    public GenericService(Class<Dao> daoClass) {
        //map entity manager & dao
        //code removed for readability
    }

    public M save(M entity) {
        EntityTransaction tx = em.getTransaction();
        tx.begin();
        entity = dao.save(entity); //IntelliJ complains about this
        tx.commit();

        return entity;
    }
}
4

2 に答える 2

1

IntellijIDEA では、カーソルをエラーに合わせてから ALT + ENTER を使用すると、intellij はおそらく次の結果をキャストすることを提案します。

dao.save(entity)

「M」として

entity = (M) dao.save(entity); 
于 2013-02-18T21:46:03.457 に答える