Java : Class inheriting self

后端 未结 8 1833
悲&欢浪女
悲&欢浪女 2021-02-15 11:21

I know this is pointless: I just find it funny and I want to inquire more about the mechanics of what happens when you create a class that inherits itself, resulting in a stack

8条回答
  •  不知归路
    2021-02-15 11:46

    The example you posted could get problematic if we change it a bit more:

    public class Outside {
    
        public class Inside extends Outside {
    
                public Inside(int val) {
            }
    
        }
    
        private Inside i;
    
        public Outside() {
            i = new Inside();
        }
    }
    

    But this is not really related to the fact that Inside is an inner class of Outside, it could have happened with separate top-level-classes identically.

提交回复
热议问题