如何声明实现类的java接口字段应该优化该字段 [英] how can I declare java interface field that implement class should refine that field
本文介绍了如何声明实现类的java接口字段应该优化该字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何声明实现类的java接口字段应该优化该字段?
How can I declare java interface field that implement class should refine that field ?
例如
public interface IWorkflow{
public static final String EXAMPLE;// interface field
public void reject();
}
// and implement class
public class AbstWorkflow implements IWorkflow
{
public static final String EXAMPLE = "ABCD"; /*MUST HAVE*/
public void reject(){}
...
}
谢谢。
推荐答案
参见规范。接口中没有覆盖字段 - 它们只是隐藏在某些上下文中,而在其他上下文中则不明确。我只是远离。而是在接口中放置一个getter(getEXAMPLE())
See section 9.3 of the specification. There is no overriding of fields in interfaces - they are just hidden in some contexts, and ambiguous in others. I'd just stay away. Instead put a getter in the interface (getEXAMPLE())
这篇关于如何声明实现类的java接口字段应该优化该字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文