How to force derived class to call super method? (Like Android does)

Peterdk picture Peterdk · Nov 18, 2010 · Viewed 44.7k times · Source

I was wondering, when creating new Activity classes and then overriding the onCreate() method, in eclipse I always get auto added: super.onCreate(). How does this happen? Is there a java keyword in the abstract or parent class that forces this?

I don't know if it is illegal not to call the super class, but I remember in some methods that I got a exception thrown for not doing this. Is this also built-in into java? Can you use some keyword to do that? Or how is it done?

Answer

runor49 picture runor49 · Jun 9, 2015

This is added in the support annotation library:

dependencies {
    compile 'com.android.support:support-annotations:22.2.0'
}

http://tools.android.com/tech-docs/support-annotations

@CallSuper