开发者

Is it possible to forbid annotation inheritance?

开发者 https://www.devze.com 2023-03-11 07:24 出处:网络
I have a controller superclass and its subclass: public class SuperController { @Resource private A resourceA;

I have a controller superclass and its subclass:

public class SuperController {
    @Resource
    private A resourceA;
}

public class SubController extends SuperController {
    @Resource
    private B resourceB;
}

I don't use resourceA field i开发者_开发技巧n Subcontroller, but Subcontroller acts as SuperController and has the same methods. So how can I forbit the inheritance of @Resource annotation, just like that:

public class SuperController {
    **private** @Resource
    private A resourceA;
}


Sounds like you need a common abstract class if the sub-class doesn't use some of the fields of the parent class.

public abstract class AbstractController {
    // common fields.
    // common methods.
}

public class SuperController extends AbstractController {
    @Resource
    private A resourceA;
}

public class SubController extends AbstractController {
    @Resource
    private B resourceB;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消