2011-06-09 71 views
0

我有一個控制器和超它的子類:是否有可能禁止註釋繼承?

public class SuperController { 
    @Resource 
    private A resourceA; 
} 

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

我不Subcontroller使用resourceA領域,但Subcontroller作爲SuperController並且具有相同的方法。所以,我怎麼能forbit @Resource註釋的繼承,就像這樣:

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

回答

1

聽起來像是你需要一個共同的抽象類如果子類不使用一些父類的字段。

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; 
}