Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

About @override annotation in Activity callbacks

It seems in an Activity, for example, the onCreate() method, it does not make much difference if I have the @Override annotation or not. They both work. (As long as I call super.onCreate() inside the callback , it will call the parent class' method.)

Can someone tell me why we need to have the @Override annotation for life-cycle callbacks in Activity ?

I ask this because I tested without @Override annotation, my app still running successfully.

like image 328
Leem.fin Avatar asked Jan 18 '26 03:01

Leem.fin


1 Answers

This is more like a good development practice.

If by mistake you want to override a method that doesn't exist in the super class (or interfaces implemented) you'll get an error.

Think that you want to override "onCreate" but you misspell it and write "onCreatee". With that annotation, you'll get an error. Without it, you'd end up spend a lot time trying to understand why your initialization method was not working properly.

like image 189
Pedro Loureiro Avatar answered Jan 19 '26 19:01

Pedro Loureiro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!