How does this happen? Is there a java keyword in the abstract or parent class that forces this?
As you observed, on Android calls to super() are auto-edited by IDEs when you override a function, and you get lint errors if you remove the call to super.
Methods can signal that methods which override them should call them by using the @CallSuper
annotation.
E.g., see the example given by the docs:
@CallSuper
override fun onCreate(savedInstanceState: Bundle?) {}
To use this, you may need to add the annotation library to your build.gradle
:
dependencies {
implementation("androidx.annotation:annotation:1.8.0")
}
Is this also built-in into java? Can you use some keyword to do that? Or how is it done?
It's not built into Java, but other answers here show manual approaches for plain Java.
If you are on Android, I recommend just using @CallSuper
. It is "only" a linter error (not just a warning!). So if you run the linter at build time (which you should), the effect is the same: the build will fail if you don't call the super method.