4 ms·
Can you clarify your comment? I don't understand how those four types could be avoided with reified generics.
by kelseyfrancis 13y ago
Can you clarify your comment? I don't understand how those four types could be avoided with reified generics.
- pron 13y agoBecause then you'd only have Stream<T>; IntStream would be just Stream<int>. The problem with reified generics is that they bake a particular type system into the runtime. While once a desired feature, I don't think the wide JVM community wants that any more.
- darylteo 13y agoTo be fair, I don't think this is a problem with reified generics. The problem is that primitives cannot be erased to Objects in Java. Stream<int> only works in C# because int is an alias of Int32. Not because of reified generics. The above should no longer be an issue when/if we remove the primitive types in Java 10(?) as we can safely use Stream<Integer> and Predicate<Integer> (or Stream<int>).
- alkonaut 13y agoThe runtime type erasure would have to be quite clever to realize that a ArrayList<Integer> should be backed by a primitive array of ints? One alternative is to erase ArrayList<T> into all variants (One for objects and one for each primitive type). (In C# System.Int32 is a value type, and an "int" is equivalent). A List<Int32> is equivalent to a List<int> and is backed by an array of ints.)