Java polymorphism performance

403 Views Asked by At

I am profiling some java code that is calling an abstract method a great number of times. The profiler (visual vm) shows time is spent in the specialized versions of derived classes, which is normal, but there is also a big amount of time spent in the abstract method of my interface, which contains nothing. I suspect it comes from runtime type checking.

In C++, I usually use templates instead of inheritance in this critical cases to use compile time polymorphism which is faster.

What would the equivalent be in Java?

Is there a way to speed up this part of my code?

Thanks for your help,

0

There are 0 best solutions below