Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

They are kinda related in a way that Java implementation of generics does not help with devirtualization, while C++ templates / Rust traits do help by not needing virtual calls from the start.

Consider the pre- Java 1.5 sort method:

Collections.sort(List list, Comparator comparator);

If you load more than one Comparator type, then the calls to comparator are megamorphic and devirtualization won't happen unless the whole sort is inlined.

In languages like C++, you'd make it a template and the compiler would always know the target type, so no need for virtual.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: