Practical side of the ability to define a class within an interface in Java?

前端 未结 11 1310
暖寄归人
暖寄归人 2020-12-30 06:32

What would be the practical side of the ability to define a class within an interface in Java:

interface IFoo
{
    class Bar
    {
        void foobar (         


        
11条回答
  •  梦谈多话
    2020-12-30 07:07

    I think this page explains one example pretty well. You would use it to tightly bind a certain type to an interface.

    Shamelessly ripped off from the above link:

    interface employee{
        class Role{
              public String rolename;
              public int roleId;
         }
        Role getRole();
        // other methods
    }
    

    In the above interface you are binding the Role type strongly to the employee interface(employee.Role).

提交回复
热议问题