如果我们在oracle文档中看到Thread.UncaughtExceptionHandler或Map.Entry这样的定义,它们被定义为公共(public)静态接口(interface)。想知道 Java 内部是如何实现或编写的吗?因为当我们尝试创建一些类似模式的自定义接口(interface)时,编译器会在点(.)处抛出异常!
public static interface Dot.Intf{
void disp();
}
最佳答案
这是因为嵌套类型。
喜欢,
public class Thread {
public static interface UncaughtExceptionHandler {
//interface members
void uncaughtException(Thread t, Throwable e);
}
}
并且可以有一个单独的类来实现 Thread 类中定义的接口(interface)。
public class ThreadGroup implements Thread.UncaughtExceptionHandler {
//implementation to the uncaughtException method.
}
访问时,会是Thread.UncaughtExceptionHandler(){}
关于java - Thread.UncaughtExceptionHandler 或 Map.Entry 等接口(interface)中怎么会有点(.)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32778032/