用抽象方法覆盖默认接口方法 [英] Overriding default interface method with abstract method
本文介绍了用抽象方法覆盖默认接口方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我觉得它很奇怪,想知道它是否是经常使用的东西.什么时候有用?
I find it weird and was wondering if it is something that is regularly used. When can it be useful?
public interface InterA {
Object getInfo() throws Exception1;
}
public interface InterB {
public default Integer getInfo(Object s) {return 67;}
}
public interface InterC extends InterA, InterB {
@Override public abstract Integer getInfo(Object s);
}
推荐答案
它存在于默认接口方法之前.例如,一个抽象类可以使
This exists before default interface methods. For example, an abstract class can make
@Override
abstract public int hashCode();
强制子类提供 hashCode
的实现,可能是因为抽象类强加了额外的要求.
forcing subclasses to provide implementations for hashCode
, possibly because of additional requirements imposed by the abstract class.
这篇关于用抽象方法覆盖默认接口方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文