Why is Java prohibiting inheritance of inner interfaces?

前端 未结 3 1967
醉梦人生
醉梦人生 2021-02-18 21:21

I.e. why is the following \"cyclic dependency\" not possible?

public class Something implements Behavior {
    public interface Behavior {
        // ...
    }
}         


        
3条回答
  •  抹茶落季
    2021-02-18 22:08

    The simple fact that the language specs forbid it should be enough.

    Some reasons I could think of:

    • It wouldn't be useful.

    • For whatever reasons you might want to use this, I'm sure there exist better options.

    • Child classes should extend base classes, so why would you declare a base class inside its own child?

    • It would be counter-intuitive having a separate class extend your inner-class.

提交回复
热议问题