Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any harm in using super when not needed?

This message pertains strictly to Java. If a method is in a superclass there are two ways the method could be called:

foo();
super.foo();

Is there any harm in always doing the latter? As a coding style I prefer the latter because it's clear at a glance where the method call is coming from. Are there any circumstances where 'super' is going to be non-existent or not do what I think it would do?

like image 315
Pace Avatar asked Oct 03 '12 13:10

Pace


1 Answers

I think the only harm you may have is when you want to use polymorphism so, if you call foo() and some subclass overrides foo, then the effect would be different than if you call super.foo(), basically, it depends on how you are designing the code and for what purpose.

Hope this makes it clear.

like image 107
Juan Alberto López Cavallotti Avatar answered Oct 26 '22 21:10

Juan Alberto López Cavallotti