đź’ˇ Java tip: Catch mistakes at compile time annotating overridden methods with
@Override.
For example, given a class:
class Report {
void print() {
...
}
}
❌ If we extend the class without
@Override:
class PDFReport extend Report{
void prnt() {
...
}
//There is a typo, print method is not overridden
}
âś… With
@Override:
class PDFReport extend Report{
@Override
void prnt() {
...
}
//This way you get an error during compilation,
//and you are forced to fix the method name
}
#Java #Annotations