How do I force a polymorphic call to the super method?

前端 未结 7 1049
猫巷女王i
猫巷女王i 2020-12-16 15:54

I have an init method that is used and overridden through out an extensive heirarchy. Each init call however extends on the work that the previous did. So naturally, I would

7条回答
  •  鱼传尺愫
    2020-12-16 16:00

    Android actually accomplishes this in the Activity class. I'm not sure how or whether they had to build support into the runtime for it, but I'd check out the open source code for the Activity class implementation. Specifically, in any of the lifecycle methods, you have to call the corresponding super class method before you do anything otherwise it throws SuperNotCalledException.

    For instance, in onCreate(), the first thing you have to do is call super.onCreate().

提交回复
热议问题