2 ms·
Are you talking about type erasure and generics? If so I agree, but that’s unrelated to devirtualization
by NavinF 4y ago
Are you talking about type erasure and generics? If so I agree, but that’s unrelated to devirtualization
- pkolaczk 4y agoThey 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.