3 ms·
Note also that Java does have reified generics, but only for arrays. The designers of the JVM from early on did realize the advantages of reified generics. Ty
by KMag 9y ago
Note also that Java does have reified generics, but only for arrays. The designers of the JVM from early on did realize the advantages of reified generics. Type erasure is not some principled stand being made by the JVM.
- kbsletten 9y agoWell, really their hand was forced because they needed to be able to specialize all of the array-of-primative types. It's not as much they saw the advantage as they couldn't imagine a language where you can't express `byte []`. But the point stands that they could have realized that `ArrayList <byte>` is almost as fundamental and created refied generics for user-defined types as well.
- KMag 9y agoThey could have had type erasure for all arrays of non-primitives. Their hand was not forced.
- masklinn 9y ago> Note also that Java does have reified generics, but only for arrays. By that count, so does C.
- Sharlin 9y agoC has no runtime type information at all. Java knows the difference between Integer[] and Float[] at runtime but not between List<Integer> and List<Float>.
- TheCoelacanth 9y agoJava has generics but they are only reified for arrays. C has types that are only generic in the case of arrays. There is a difference. In Java I can write this function <T> String getTypeOfArray(T[] arr) { return arr.getClass().getComponentType().getName(); } and that will return the name of type T at run-time. If I instead of T[] I use List<T>, getComponentType will return null and there is no way to access what type T is at run-time. At compile time List<T> and T[] behave the same, but at runtime the List loses what type if contains. In C I can't write a function with that signature at all because it doesn't support generic functions.