我在 https://developer.android.com/training/basics/network-ops/connecting.html 中看到过这个接口(interface)声明:
public interface DownloadCallback<T> {
interface Progress {
int ERROR = -1;
int CONNECT_SUCCESS = 0;
int GET_INPUT_STREAM_SUCCESS = 1;
int PROCESS_INPUT_STREAM_IN_PROGRESS = 2;
int PROCESS_INPUT_STREAM_SUCCESS = 3;
}
void updateFromDownload(T result);
...
}
根据 https://docs.oracle.com/javase/tutorial/java/IandI/interfaceDef.html , 接口(interface)体只能包含
在这种情况下,接口(interface)主体包含另一个接口(interface)。你如何解释这个代码块?有人可以指点我正确的文档,以便我可以了解有关此方法的更多信息吗?
最佳答案
参见 JLS §9.1.4 :
The body of an interface may declare members of the interface, that is, fields (§9.3), methods (§9.4), classes (§9.5), and interfaces (§9.5).
用法很简单OuterInterface.NestedInterface
。
在您引用的代码中,嵌套接口(interface)仅用于包含常量,这样它们就不会“泄漏”到实现 DownloadCallback
的类。
关于java - 嵌套的 Java 接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49706120/