5 ms·
How do you end up with 9 copies of everything? I'm not sure I follow that. If you are passing in massive ArrayList<Integer> lists to external libraries, you ne
by astral303 11y ago
How do you end up with 9 copies of everything? I'm not sure I follow that.
If you are passing in massive ArrayList<Integer> lists to external libraries, you need to re-evaluate what you're doing. What will that external library do with this?
- TheLoneWolfling 11y agoLook at java.util.Arrays for a concrete example of the problem: static int binarySearch(byte[] a, byte key) static int binarySearch(char[] a, char key) static int binarySearch(double[] a, double key) static int binarySearch(float[] a, float key) static int binarySearch(int[] a, int key) static int binarySearch(long[] a, long key) static int binarySearch(Object[] a, Object key) static int binarySearch(short[] a, short key) This, sort of works. It's a lot of code duplication, but it's all in the library. Except that a relatively common thread goes like this: You start by having a generic array that gets passed to said binary search. It works, but it's too memory-hungry when it gets called with a primitive. So, then what do you do? Well, you go "huh, I could specialize". And then you start specializing, and realize that every function that calls binarySearch with a generic type also needs 8 implementations (would be 9, but no sane person would binary search a boolean[] ). Basically, its complexity that you cannot even punt off to an external library. If you have code that needs to be able to be called with generics without inefficiencies for primitive types, you'll end up with ~9x code duplication at a minimum.