假设您有以下EJB 3接口/类:
public interface Repository{ public void delete(E entity); } public abstract class AbstractRepository implements Repository { public void delete(E entity){ //... } } public interface FooRepository { //other methods } @Local(FooRepository.class) @Stateless public class FooRepositoryImpl extends AbstractRepository implements FooRepository { @Override public void delete(Foo entity){ //do something before deleting the entity super.delete(entity); } //other methods }
然后另一个访问FooRepository
bean的bean:
//... @EJB private FooRepository fooRepository; public void someMethod(Foo foo) { fooRepository.delete(foo); } //...
但是,当FooRepository
调用bean 的delete方法时,永远不会执行重写方法.相反,只执行定义的delete方法的实现AbstractRepository
.
我做错了什么,或者只是Java/EJB 3的限制,泛型和继承不能很好地协同工作呢?