【问题标题】:Overriding a method of generic super class that returns T覆盖返回 T 的泛型超类的方法
【发布时间】:2013-02-19 10:58:24
【问题描述】:

超级类看起来是这样的:

public class DomainRepository<T> {
    public DomainRepository(Class genericType) {
        this.genericType = genericType;
    }

    @Transactional(readOnly = true)
    public T get(final long id) {
        return (T) sessionFactory.getCurrentSession().get(genericType, id);
    }
}

子类是这样的

public class FooRepository extends DomainRepository<Foo> {
    public FooRepository(){
        super(Foo.class);
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public Foo get(final Long id) { //blah blah

但是我的 IDE 在 @Override 注释上突出显示错误 sayign 方法确实覆盖了任何东西...?

【问题讨论】:

    标签: java generics inheritance subclass


    【解决方案1】:

    好像Longlong 不匹配。

    【讨论】:

    • ffs。非常感谢,这消除了错误。允许时将接受。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-22
    • 2020-07-16
    • 2020-03-14
    • 1970-01-01
    • 2014-04-18
    • 2012-03-01
    相关资源
    最近更新 更多