Cyclic inheritance when implementing inner interface in enum

后端 未结 3 1569
别那么骄傲
别那么骄傲 2020-12-14 14:16

I have the following implementation that gives a compiler error:

public enum FusionStat implements MonsterStatBuilderHelper {
    ATTACK {
        @Override
         


        
3条回答
  •  没有蜡笔的小新
    2020-12-14 15:07

    This would be because you are implementing (coding) the interface you are implementing (inheriting) inside of the class that is inheriting from that class.

    I wish I could make that sentence better...

    But here is a visual example.

    Class A implements Interface B {
    
        Interface B {
        }
    }
    

    As far as I know, this is not allowed. You need to define the interface outside of the class (in this case, an Enum).

    Like so:

    Interface B {
    }
    
    Class A implements Interface B {
    }
    

    Best practice is probably to break them up into different files.

提交回复
热议问题