Nested class inside an interface

孤街浪徒 提交于 2019-12-01 05:15:38

You would use it to tightly bind a certain type to an interface. Read This page for further information and an example of defining a class inside an interface.

The uses are the same that a class nested in another class: it allows scoping the class to the interface. You could imagine something like this:

public interface Switch {

    public enum Status {
        ON, OFF;
    }

    void doSwitch();
    Status getStatus();
}

It avoids defining a top-level class named SwitchStatus (because Status could be a too generic name).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!